# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378723 | 2021-03-17T03:34:01 Z | daniel920712 | Chessboard (IZhO18_chessboard) | C++14 | 59 ms | 8816 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; vector < pair < int , int > > in[100005]; vector < pair < int , int > > out[100005]; vector < int > have; int main() { long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r; scanf("%lld %lld",&N,&M); for(i=1;i<N;i++) if(N%i==0) have.push_back(i); while(M--) { scanf("%lld %lld %lld %lld",&a,&b,&c,&d); in[a].push_back(make_pair(b,d)); out[c+1].push_back(make_pair(b,d)); } for(auto i:have) { t=0; t2=0; a=0; b=0; c=0; d=0; a=N/i/2*i; c=N/i/2*i; if(N/i%2) c+=i; for(j=1;j<=N;j++) { for(auto k:out[j]) { l=(k.first-1)/i+1; r=(k.second-1)/i-1; x=y=(r-l+1)/2; if((r-l+1)%2) { if(l%2==0) x++; else y++; } d-=x*i; c+=x*i; b-=y*i; a+=y*i; if((k.first-1)/i==(k.second-1)/i) { if((k.first-1)/i%2) { b-=(k.second-k.first+1); a+=(k.second-k.first+1); } else { d-=(k.second-k.first+1); c+=(k.second-k.first+1); } } else { if((k.first-1)/i%2) { b-=i-((k.first-1)%i); a+=i-((k.first-1)%i); } else { d-=i-((k.first-1)%i); c+=i-((k.first-1)%i); } if((k.second-1)/i%2) { b-=(k.second-1)%i+1; a+=(k.second-1)%i+1; } else { d-=(k.second-1)%i+1; c+=(k.second-1)%i+1; } } } for(auto k:in[j]) { l=(k.first-1)/i+1; r=(k.second-1)/i-1; x=y=(r-l+1)/2; if((r-l+1)%2) { if(l%2==0) x++; else y++; } d+=x*i; c-=x*i; b+=y*i; a-=y*i; if((k.first-1)/i==(k.second-1)/i) { if((k.first-1)/i%2) { b+=(k.second-k.first+1); a-=(k.second-k.first+1); } else { d+=(k.second-k.first+1); c-=(k.second-k.first+1); } } else { if((k.first-1)/i%2) { b+=i-((k.first-1)%i); a-=i-((k.first-1)%i); } else { d+=i-((k.first-1)%i); c-=i-((k.first-1)%i); } if((k.second-1)/i%2) { b+=(k.second-1)%i+1; a-=(k.second-1)%i+1; } else { d+=(k.second-1)%i+1; c-=(k.second-1)%i+1; } } } if((j-1)/i%2) { t+=a; t+=d; t2+=b; t2+=c; } else { t2+=a; t2+=d; t+=b; t+=c; } } ans=min(ans,t); ans=min(ans,t2); } printf("%lld\n",ans); return 0; } /* 6 8 3 3 3 3 1 2 1 2 3 4 3 4 5 5 5 5 4 3 4 3 4 4 4 4 2 1 2 1 3 6 3 6 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4972 KB | Output is correct |
2 | Correct | 4 ms | 4972 KB | Output is correct |
3 | Correct | 23 ms | 4972 KB | Output is correct |
4 | Correct | 22 ms | 4972 KB | Output is correct |
5 | Correct | 4 ms | 4972 KB | Output is correct |
6 | Correct | 21 ms | 4972 KB | Output is correct |
7 | Correct | 23 ms | 4972 KB | Output is correct |
8 | Correct | 3 ms | 4972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 59 ms | 8816 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 4972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 4972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 59 ms | 8816 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4972 KB | Output is correct |
2 | Correct | 4 ms | 4972 KB | Output is correct |
3 | Correct | 23 ms | 4972 KB | Output is correct |
4 | Correct | 22 ms | 4972 KB | Output is correct |
5 | Correct | 4 ms | 4972 KB | Output is correct |
6 | Correct | 21 ms | 4972 KB | Output is correct |
7 | Correct | 23 ms | 4972 KB | Output is correct |
8 | Correct | 3 ms | 4972 KB | Output is correct |
9 | Incorrect | 59 ms | 8816 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |