#include #define cin fin #define cout fout #define endl '\n' using namespace std; const int maxn = 300; int a[maxn+3][maxn+3],tek[maxn+3][maxn+3]; int ans[10],cnt[10],ind[10],wins[10]; int tables[maxn+3][maxn+3]; int otg[10][maxn+3][maxn+3]; char c; int i,j,p,q,n,m,k,d,parties,pos,br; //ifstream fin("test.txt"); ifstream fin("gerrymandering.in"); ofstream fout("gerrymandering.out"); void read() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>d>>parties; for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { cin>>a[i][j]; //a[i][j]=c-'0'; } } } void wrrite(int ind) { for(int ii=1; ii<=n; ii++) for(int jj=1; jj<=n; jj++) otg[ind][ii][jj]=tables[ii][jj]; } void build(int lrow,int lcol,int rrow,int rcol,int p,int q) { int lc = lcol; while(lrow<=rrow) { br++; ///vzimame podtablica ot l,r - razmeri p,q for(int x=lrow; xmaxx) maxx=cnt[jjj],which=jjj; else if(cnt[jjj]==maxx) which=-1; cnt[jjj]=0; } if(which!=-1) wins[which]++; lc+=q; if(lc>rcol) lrow+=p,lc=lcol; } } void prrint() { for(int ii=1; ii<=n; ii++) { for(int jj=1; jj<=n; jj++) cout<ans[jjj] || otg[jjj][1][1]==0) ans[jjj]=wins[jjj],wrrite(jjj); wins[jjj]=0; } } void construct_tables() { k = (n*n)/d; vector del; for(i=1; i<=sqrt(k); i++) if(k%i==0)del.push_back(i),del.push_back(k/i); p=sqrt(k); if(k%p==0 && k/p==p) del.pop_back(); for(auto i:del) { p=i; q=k/i; if(n%p!=0 || n%q!=0) continue; // cout<<"dimensions "<=n)continue; q = k/del[i]; if(n%q!=0)continue; for(int j=0; j=n)continue; int q2=k/del[j]; if(n%q2!=0) continue; int cnttt=0; for(int g=1; g<=n/p; g++) { // cout<n)continue; for(int j=0; jn) continue; for(int g=1; g<=n/q; g++) { // cout<