CodeChef submission 184252 (C++ 4.3.2) plaintext list. Status: AC, problem M3, contest FEB10. By codegambler (codegambler), 2010-02-09 14:03:32.
//===================================================================================== // Filename: M3.cpp // Description: // Created: 02/01/2010 05:04:19 PM // Author: pankaj kumar, pankaj4u4m@gmail.com //===================================================================================== #include <cassert>//c headers in c++ #include <cctype> #include <cfloat> #include <cmath> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm>//c++ headers #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <new> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> using namespace std; /*START OF TEMPLATE:BY_PANKAJ_CODEGAMBLER*/ #define INF 2000000000//::INF #define VAR(x,a) __typeof(a) x=(a)//::VAR( #define FE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)//::FE( #define FOR(i,a,b) for(int i=(int)(a),_b=(int)(b) ; i < _b;++i)//::FOR( #define FORR(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)//::FORR( #define REP(i,n) FOR(i,0,n)//::REP( #define ALL(c) (c).begin(),(c).end()//::ALL( #define SZ(c) (int)(c).size()//::SZ( #define PB push_back//::PB #define PF push_front//::PF #define V(x) vector< x >//::V( #define VI V(int)//::VI #define VVI V(VI)//::VII #define VS V(string)//::VS #define PI pair< int,int >//::PI #define MP make_pair//::MP #define pi 3.14159265358979323846//::pi const double eps=1e-11;//::eps typedef long long LL;//::LL typedef unsigned long long ULL;//::ULL typedef long double LD;//::LD /* Input Output Function */ #define BUFSIZE (1<<16) char BUF[BUFSIZE+1], *inp=BUF; #define DIG(a) (((a)>='0')&&((a)<='9'))//::DIG( #define getChar(t) {if(!*inp){BUF[fread(BUF,1,BUFSIZE,stdin)]=0;inp=BUF;}t=*inp++;}//::getChar( #define getInt(j) {int t;char sign;do{sign = t;getChar(t);}while(!DIG(t));j=t-'0'; getChar(t);while(DIG(t)){j=10*j+(t-'0');getChar(t);}if(sign == '-') j = -j;}//::getInt( /* Only for Debugging */ #define out(__debug) cout << #__debug<< "=" <<__debug << endl;//::out( template<class T> void outC(T A)//::outContainer template<class T> void outA(T A[],int n)//::outArray { cout<<"{"; for (int i=0;i<n;i++) cout<<A[i]<<" "; cout<<"}"<<endl;} template<class T> void outV(vector<T> A,int n=-1)//::outVector { if (n<0) n=SZ(A); cout<<"{"; for (int i=0;i<n;i++) cout<<A[i]<<" "; cout<<"}"<<endl;} template<class T> static void split(const string &s, vector<T> &out)//::split( {istringstream in(s);out.clear();copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));} /*END TEMPLATE:BY_PANKAJ_CODEGAMBLER*/ int ans[150]; int n; //int tog_sz=0; int a[150][150]; char res[150]; int counter = 0; int col[150]; int chk =0; void solve(){ REP(i, n)REP(j, n){ if( a[i][j] == 1) ans[i]++; } int ansm = *max_element(ans, ans+n); //int nby2 = (n-1)/2; REP(row, n){ chk = 0; REP(i, n){ if( a[i][row] == 1){col[i]++;chk = 1;} } counter = 0; REP(i, n){ if( a[row][i] == 1||a[row][i] == 2) counter ++; } if( counter >= n/2 ){ int fl = 0; if( counter == n/2) { REP(i, n){ int cnt =0 ; REP(j, n){ if( a[i][j] == 1|| a[i][j] == 2) cnt++; } // out(cnt); if( cnt < n/2){fl =1 ;break;} } } if( fl == 0 && counter >= ansm){ //now matter VI maxele; REP(i, n){ if( ans[i] == ansm ) maxele.PB(i); } int sz = SZ(maxele); int f = 0; REP(i, sz)FOR(j, i+1, sz){ if( a[maxele[i]][maxele[j]] == 2) f=1; } if( f== 1) ansm ++; if( counter >= ansm) res[row] = '1'; } } } } int main() { // freopen("M3.cppin","r",stdin); int T; //scanf("%d", &T); getInt(T); while(T--){ getInt(n); // memset(a, 0, sizeof a); REP(i, n)REP(j, n) getInt(a[i][j]); // scanf("%d", &a[i][j]); //input over; solve(); res[n] = 0; } return 0; }
Comments

