CodeChef submission 131082 (C++ 4.0.0-8) plaintext list. Status: AC, problem JX, contest NOV09. By akhilravidas (Akhil Ravidas), 2009-11-11 14:55:50.
// 2055 #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <string> #include <cstdio> #include <cctype> #include <vector> #include <cassert> #include <iomanip> #include <string.h> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; typedef pair<int,int> PI; #define _DEBUG 1 #define DEBUG if(_DEBUG) #define dbg(x) DEBUG{cerr << #x << " -> " << (x) << "\t";} #define dbge(x) DEBUG{cerr << #x << " -> " << (x) << endl;} namespace INPUT{ const int mlen = 1<<16; char buf[mlen+10],*pst,*pen; int parse,sgn,aaa; inline void getit(){ pst = buf , pen = pst + read ( 0 , buf, mlen ); } inline void nextChar() { pst ++; if ( pst == pen ) getit(); } int nextInt() { sgn=0; parse = 0; if (*pst == '-' ) sgn=1,nextChar(); else parse = parse*10+(*(pst)&15),nextChar() ; } return parse*=(sgn?-1:1); } }; const int mn=400; int mat[512][512],A[512],Top,D,S,deg[512],deg1[512],V[512],tmp[512],result[512],SZ,B[512],pres[512]; double cps = CLOCKS_PER_SEC , offset, threshold; int bestlen=-1,bestcut,cut,c; vector < int > adj[512]; inline int check ( int top ) { int ndance = D,i,j; for ( i=0;i<D;i++ ) { for ( j=0;j<top;j++ ) if ( mat[i][tmp[j]] ) goto nxt; else ndance --; if ( ndance <= bestlen ) return -1; pres[i] = 0; nxt:; } for ( i=0;i<top;i++ ) for ( vector<int>::iterator it = adj[tmp[i]].begin();it != adj[tmp[i]].end();it++ ) { j=*it; if ( pres[j] ) { pres[j] --; if ( !pres[j] ) { ndance --; if ( ndance <= bestlen ) return -1; } } } return ndance; } int cmp(int a, int b ) { return /*deg1[a]/DMAX +*/ deg[a] > /*deg1[b]/DMAX + */ deg[b]; } int main() { threshold = start / cps; int i,j,c; INPUT::getit(); D=INPUT::nextInt(); S=INPUT::nextInt(); for ( i=0;i<D;i++ ) { B[i]=INPUT::nextInt(); } for ( i=0;i<S;i++ ) V[i]=i; for ( i=0;i<D;i++ ) for ( j=0;j<S;j++ ) { c=mat[i][j]=INPUT::nextInt(); if (c)deg[j]++ ; } for ( i=0;i<D;i++ ) for ( j=0;j<S;j++ ) if ( !mat[i][j] ) adj[j].push_back(i); sort ( V , V+S , cmp ); bestlen = deg[V[0]]; result[0] = V[0]; SZ = 1; bool found; int Limit = 200; Limit=min(Limit,S); #define F(A,B) (double(A)*B*B) threshold += 12.*F(D,S)/F(500,500); threshold += 1; { found = false; if ( j < mn ) { { c=check(i+1); if (bestlen<c) bestlen=c,cut=i+1,found=true; } } else { { c=check(i+1); if (bestlen<c) bestlen=c,cut=i+1,found=true; } } if ( found ) { SZ = cut; } random_shuffle(V,V+S); } // dbge(j); // dbge(mn); // dbge(bestlen); for ( i=0;i<SZ;i++ ) return 0; }
Comments

