# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91259 | 2018-12-26T18:27:39 Z | Vardanyan | Chessboard (IZhO18_chessboard) | C++14 | 31 ms | 5904 KB |
#include<bits/stdc++.h> using namespace std; const int N = 1000*100+5; long long tox_type[N]; long long pref_type1[N]; long long pref_type2[N]; int X1[N],X2[N],Y1[N],Y2[N]; long long syun_pref_type[N]; int main() { int n,k; scanf("%d%d",&n,&k); for(int i = 1;i<=k;i++) scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]); long long ans = 100000000000000005; for(int w = 1;w<=n/2;w++){ if(n%w) continue; memset(tox_type,0,sizeof tox_type); memset(pref_type1,0,sizeof pref_type1); memset(pref_type2,0,sizeof pref_type2); memset(syun_pref_type,0,sizeof syun_pref_type); for(int j = 1;j<=n;j++){ int x = (j-1)/w; if(x%2 == 0){ // sev tox_type[j] = 1; syun_pref_type[j] = syun_pref_type[j-1]+1; } else{ // spitak tox_type[j] = 2; syun_pref_type[j] = syun_pref_type[j-1]; } } for(int j = 1;j<=n;j++){ int x = (j-1)/w; if(x%2 == 0){ pref_type1[j] = pref_type1[j-1]+1; pref_type2[j] = pref_type2[j-1]; } else{ pref_type1[j] = pref_type1[j-1]; pref_type2[j] = pref_type2[j-1]+1; } } long long need = 0; for(int i = 1;i<=n;i++){ if(tox_type[i] == 1) need+=pref_type1[n]; else need+=pref_type2[n]; } /*if(w == 2){ cout<<need<<endl; }*/ for(int i = 1;i<=k;i++){ long long x1 = X1[i],y1 = Y1[i]; long long x2 = X2[i],y2 = Y2[i]; long long qan_tp1 = syun_pref_type[x2]-syun_pref_type[x1-1]; long long qan_tp2 = (x2-x1+1)-qan_tp1; // if(tox_type[x1] == 2) swap(qan_tp1,qan_tp2); need-=(qan_tp1*(pref_type1[y2]-pref_type1[y1-1])+qan_tp2*(pref_type2[y2]-pref_type2[y1-1])); need+=(qan_tp1*((y2-y1+1)-(pref_type1[y2]-pref_type1[y1-1]))+qan_tp2*((y2-y1+1)-(pref_type2[y2]-pref_type2[y1-1]))); /* if(w == 2){ cout<<need<<endl; }*/ } ans = min(ans,need); } cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3448 KB | Output is correct |
2 | Incorrect | 5 ms | 3448 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 5904 KB | Output is correct |
2 | Incorrect | 11 ms | 5904 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 5904 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 5904 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 5904 KB | Output is correct |
2 | Incorrect | 11 ms | 5904 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3448 KB | Output is correct |
2 | Incorrect | 5 ms | 3448 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |