#include <bits/stdc++.h>
using namespace std;
#define N 200002
#define ff first
#define ss second
#define ll long long
vector<int> di;
ll dif[200005];
ll res = 0x3f3f3f3f3f3f3f3f;
int get(int x, int d){
int r = x / (2 * d) * d;
int t = x % (2 * d);
return r + min(t, d);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
cin>>n>>k;
for(int i = 1; i < n; i++)
if(n % i == 0) di.push_back(i);
for(int i = 0; i < di.size(); i++)
dif[i] = 1LL * n * n - 1LL * n * n / (1LL * di[i] * di[i]) / 2 * (1LL * di[i] * di[i]);
while(k--){
int x1, x2, y1, y2;
cin>>x1>>y1>>x2>>y2;
for(int i = 0; i < di.size(); i++){
int ox, ex, oy, ey;
ex = get(x2, di[i]) - get(x1 - 1, di[i]);
ox = x2 - x1 + 1 - ex;
ey = get(y2, di[i]) - get(y1 - 1, di[i]);
oy = y2 - y1 + 1 - ey;
dif[i] -= 1LL * ex * ey + 1LL * ox * oy;
dif[i] += 1LL * ex * oy + 1LL * ey * ox;
}
}
for(int i = 0; i < di.size(); i++){
res = min(res, min(dif[i], 1LL * n * n - dif[i]));
}
cout<<res;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++)
~~^~~~~~~~~~~
chessboard.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++){
~~^~~~~~~~~~~
chessboard.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < di.size(); i++){
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1796 KB |
Output is correct |
2 |
Correct |
9 ms |
888 KB |
Output is correct |
3 |
Correct |
20 ms |
1272 KB |
Output is correct |
4 |
Correct |
22 ms |
1144 KB |
Output is correct |
5 |
Correct |
27 ms |
1656 KB |
Output is correct |
6 |
Correct |
18 ms |
1272 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
1144 KB |
Output is correct |
9 |
Correct |
43 ms |
2412 KB |
Output is correct |
10 |
Correct |
25 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
388 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
388 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
13 ms |
760 KB |
Output is correct |
17 |
Correct |
33 ms |
1656 KB |
Output is correct |
18 |
Correct |
41 ms |
1940 KB |
Output is correct |
19 |
Correct |
73 ms |
1780 KB |
Output is correct |
20 |
Correct |
80 ms |
1912 KB |
Output is correct |
21 |
Correct |
32 ms |
1656 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
22 ms |
1016 KB |
Output is correct |
24 |
Correct |
38 ms |
1784 KB |
Output is correct |
25 |
Correct |
7 ms |
504 KB |
Output is correct |
26 |
Correct |
26 ms |
1272 KB |
Output is correct |
27 |
Correct |
32 ms |
1528 KB |
Output is correct |
28 |
Correct |
40 ms |
1916 KB |
Output is correct |
29 |
Correct |
14 ms |
884 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1796 KB |
Output is correct |
2 |
Correct |
9 ms |
888 KB |
Output is correct |
3 |
Correct |
20 ms |
1272 KB |
Output is correct |
4 |
Correct |
22 ms |
1144 KB |
Output is correct |
5 |
Correct |
27 ms |
1656 KB |
Output is correct |
6 |
Correct |
18 ms |
1272 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
1144 KB |
Output is correct |
9 |
Correct |
43 ms |
2412 KB |
Output is correct |
10 |
Correct |
25 ms |
1528 KB |
Output is correct |
11 |
Correct |
2 ms |
388 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
428 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
13 ms |
760 KB |
Output is correct |
27 |
Correct |
33 ms |
1656 KB |
Output is correct |
28 |
Correct |
41 ms |
1940 KB |
Output is correct |
29 |
Correct |
73 ms |
1780 KB |
Output is correct |
30 |
Correct |
80 ms |
1912 KB |
Output is correct |
31 |
Correct |
32 ms |
1656 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
22 ms |
1016 KB |
Output is correct |
34 |
Correct |
38 ms |
1784 KB |
Output is correct |
35 |
Correct |
7 ms |
504 KB |
Output is correct |
36 |
Correct |
26 ms |
1272 KB |
Output is correct |
37 |
Correct |
32 ms |
1528 KB |
Output is correct |
38 |
Correct |
40 ms |
1916 KB |
Output is correct |
39 |
Correct |
14 ms |
884 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
69 ms |
2296 KB |
Output is correct |
42 |
Correct |
47 ms |
2552 KB |
Output is correct |
43 |
Correct |
55 ms |
2296 KB |
Output is correct |
44 |
Correct |
45 ms |
2600 KB |
Output is correct |
45 |
Correct |
46 ms |
2716 KB |
Output is correct |
46 |
Correct |
79 ms |
2680 KB |
Output is correct |
47 |
Correct |
40 ms |
2416 KB |
Output is correct |
48 |
Correct |
49 ms |
2424 KB |
Output is correct |
49 |
Correct |
43 ms |
2552 KB |
Output is correct |
50 |
Correct |
236 ms |
2584 KB |
Output is correct |
51 |
Correct |
251 ms |
2680 KB |
Output is correct |
52 |
Correct |
236 ms |
2424 KB |
Output is correct |
53 |
Correct |
256 ms |
2680 KB |
Output is correct |
54 |
Correct |
232 ms |
2424 KB |
Output is correct |
55 |
Correct |
259 ms |
2680 KB |
Output is correct |
56 |
Correct |
223 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
30 ms |
1796 KB |
Output is correct |
10 |
Correct |
9 ms |
888 KB |
Output is correct |
11 |
Correct |
20 ms |
1272 KB |
Output is correct |
12 |
Correct |
22 ms |
1144 KB |
Output is correct |
13 |
Correct |
27 ms |
1656 KB |
Output is correct |
14 |
Correct |
18 ms |
1272 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
18 ms |
1144 KB |
Output is correct |
17 |
Correct |
43 ms |
2412 KB |
Output is correct |
18 |
Correct |
25 ms |
1528 KB |
Output is correct |
19 |
Correct |
2 ms |
388 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
428 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
13 ms |
760 KB |
Output is correct |
35 |
Correct |
33 ms |
1656 KB |
Output is correct |
36 |
Correct |
41 ms |
1940 KB |
Output is correct |
37 |
Correct |
73 ms |
1780 KB |
Output is correct |
38 |
Correct |
80 ms |
1912 KB |
Output is correct |
39 |
Correct |
32 ms |
1656 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
22 ms |
1016 KB |
Output is correct |
42 |
Correct |
38 ms |
1784 KB |
Output is correct |
43 |
Correct |
7 ms |
504 KB |
Output is correct |
44 |
Correct |
26 ms |
1272 KB |
Output is correct |
45 |
Correct |
32 ms |
1528 KB |
Output is correct |
46 |
Correct |
40 ms |
1916 KB |
Output is correct |
47 |
Correct |
14 ms |
884 KB |
Output is correct |
48 |
Correct |
3 ms |
376 KB |
Output is correct |
49 |
Correct |
69 ms |
2296 KB |
Output is correct |
50 |
Correct |
47 ms |
2552 KB |
Output is correct |
51 |
Correct |
55 ms |
2296 KB |
Output is correct |
52 |
Correct |
45 ms |
2600 KB |
Output is correct |
53 |
Correct |
46 ms |
2716 KB |
Output is correct |
54 |
Correct |
79 ms |
2680 KB |
Output is correct |
55 |
Correct |
40 ms |
2416 KB |
Output is correct |
56 |
Correct |
49 ms |
2424 KB |
Output is correct |
57 |
Correct |
43 ms |
2552 KB |
Output is correct |
58 |
Correct |
236 ms |
2584 KB |
Output is correct |
59 |
Correct |
251 ms |
2680 KB |
Output is correct |
60 |
Correct |
236 ms |
2424 KB |
Output is correct |
61 |
Correct |
256 ms |
2680 KB |
Output is correct |
62 |
Correct |
232 ms |
2424 KB |
Output is correct |
63 |
Correct |
259 ms |
2680 KB |
Output is correct |
64 |
Correct |
223 ms |
2424 KB |
Output is correct |
65 |
Correct |
2 ms |
504 KB |
Output is correct |
66 |
Correct |
2 ms |
376 KB |
Output is correct |
67 |
Correct |
242 ms |
2652 KB |
Output is correct |
68 |
Correct |
242 ms |
2552 KB |
Output is correct |
69 |
Correct |
211 ms |
2296 KB |
Output is correct |
70 |
Correct |
232 ms |
2680 KB |
Output is correct |
71 |
Correct |
229 ms |
2552 KB |
Output is correct |
72 |
Correct |
228 ms |
2528 KB |
Output is correct |
73 |
Correct |
219 ms |
2424 KB |
Output is correct |
74 |
Correct |
240 ms |
2552 KB |
Output is correct |
75 |
Correct |
227 ms |
2424 KB |
Output is correct |
76 |
Correct |
244 ms |
2652 KB |
Output is correct |
77 |
Correct |
69 ms |
2708 KB |
Output is correct |
78 |
Correct |
46 ms |
2424 KB |
Output is correct |
79 |
Correct |
54 ms |
2300 KB |
Output is correct |
80 |
Correct |
56 ms |
2420 KB |
Output is correct |
81 |
Correct |
54 ms |
2292 KB |
Output is correct |
82 |
Correct |
54 ms |
2524 KB |
Output is correct |
83 |
Correct |
45 ms |
2472 KB |
Output is correct |
84 |
Correct |
158 ms |
2672 KB |
Output is correct |
85 |
Correct |
258 ms |
2676 KB |
Output is correct |
86 |
Correct |
3 ms |
376 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |
88 |
Correct |
259 ms |
2712 KB |
Output is correct |
89 |
Correct |
51 ms |
760 KB |
Output is correct |
90 |
Correct |
2 ms |
376 KB |
Output is correct |