#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=1e9;
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
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 |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
30 ms |
1188 KB |
Output is correct |
17 |
Correct |
73 ms |
2840 KB |
Output is correct |
18 |
Correct |
108 ms |
3348 KB |
Output is correct |
19 |
Correct |
294 ms |
3128 KB |
Output is correct |
20 |
Correct |
319 ms |
3308 KB |
Output is correct |
21 |
Correct |
70 ms |
2748 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
68 ms |
1504 KB |
Output is correct |
24 |
Correct |
99 ms |
3052 KB |
Output is correct |
25 |
Correct |
13 ms |
456 KB |
Output is correct |
26 |
Correct |
60 ms |
1996 KB |
Output is correct |
27 |
Correct |
98 ms |
2412 KB |
Output is correct |
28 |
Correct |
107 ms |
3196 KB |
Output is correct |
29 |
Correct |
30 ms |
1224 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
72 ms |
2232 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |