This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct c {
long long int x1, y1, x2, y2;
};
c coor [100010];
vector <int> di;
long long int uk1=0; long long int sol=0;
long long int uk2=0; long long int sol2=0;
long long int D;
long long int solve ( long long int x, long long int y, long long int p){
if (x<0 || y<0) return 0;
long long int ans=0; long long int r1, r2;
long long int t1=x/D; long long int t2=y/D;
if (t1%2==1) r1=(t1/2+1)*D;
else r1=(t1/2)*D+(x%D);
if (t1%2==1) r2=(t1/2)*D+(x%D);
else r2=(t1/2)*D;
if (t2%2==1) ans=(t2/2+1)*r1*D+(t2/2)*r2*D+r2*(y%D);
else ans=(t2/2)*r1*D+(t2/2)*r2*D+r1*(y%D);
if (p) ans=(x*y)-ans;
return ans;
}
void check (c s, long long int d){
D=d;
long long int x1=s.x1; long long int x2=s.x2; long long int y1=s.y1; long long int y2=s.y2; long long int poc=sol, poc2=sol2; //x1--; x2--; y1--; y2--;
sol+=solve (x2, y2, 0)-solve (x2, y1-1, 0)-solve (x1-1, y2, 0)+solve (y1-1, x1-1, 0); uk1+=((x2-x1+1)*(y2-y1+1)-(sol-poc));
sol2+=solve (x2, y2, 1)-solve (x2, y1-1, 1)-solve (x1-1, y2, 1)+solve (y1-1, x1-1, 1); uk2+=((x2-x1+1)*(y2-y1+1)-(sol2-poc2));
//cout << sol << " " << sol2 << endl;
return ;
}
int main(){
long long int n, k; cin >> n >> k;
for ( long long int i=0; i<k; i++){
cin >> coor [i].x1 >> coor [i].y1 >> coor [i].x2 >> coor [i].y2;
}
for ( long long int i=1; i<n; i++){
if (n%i==0) di.push_back (i);
}
long long int ans=1e18;
for ( long long int i=0; i<di.size (); i++){
sol=0; sol2=0; uk1=0; uk2=0;
for ( long long int j=0; j<k; j++){
check (coor [j], di [i]);
}
long long int u1, u2;
u1=(((n/di[i])*(n/di[i]))/2*di[i]*di[i]);
u2=n*n-u1;
ans=min(ans, min(u1-uk1+sol, u2-uk2+sol2));
//cout << u1 << " " << u2 << endl;
//cout << min(u1-uk1+sol, u2-uk2+sol2) << endl;
}
cout << ans;
return 0;
}
Compilation message (stderr)
chessboard.cpp: In function 'int main()':
chessboard.cpp:43:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for ( long long int i=0; i<di.size (); i++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |