#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin() x.end()
#define MOD (1e9+7)
const int N = 1e6;
ll n, k, ans = 1e18;
vector<array<ll, 4>> vv;
ll wh(ll x, ll y, ll d){
x++, y++;
if(x <= 0 || y <= 0) return 0;
ll res = (x / d) * (y / d) / 2 * d * d;
if(x % (2*d) >= d){
ll y1 = y / (2*d) * 2*d;
res += y1 / (2*d) * (x % d) * d;
res += (x % d) * min(d, y % (2*d));
}else{
ll y1 = y / (2*d) * 2*d;
res += y1 / (2*d) * (x % d) * d;
}
if(y % (2*d) >= d){
ll x1 = x / (2*d) * 2*d;
res += x1 / (2*d) * (y % d) * d;
res += (y % d) * min(d, x % (2*d));
}else{
ll x1 = x / (2*d) * 2*d;
res += x1 / (2*d) * (y % d) * d;
}
return res;
}
ll bl(ll x, ll y, ll d){
x++, y++;
if(x <= 0 || y <= 0) return 0;
return x * y - wh(x - 1, y - 1, d);
}
void solve(){
cin >> n >> k;
int a = 0;
for(int i = 0; i < k; ++i){
int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
vv.pb({x1-1,y1-1,x2-1,y2-1});
}
for(ll i = 1; i < n; ++i){
if(n % i == 0){
for(int rep = 0; rep < 2; ++rep){
ll c = 0;
for(auto v: vv){
ll white = wh(v[2], v[3], i) - wh(v[0] - 1, v[3], i) - wh(v[2], v[1] - 1, i) + wh(v[0] - 1, v[1] - 1, i);
ll black = bl(v[2], v[3], i) - bl(v[0] - 1, v[3], i) - bl(v[2], v[1] - 1, i) + bl(v[0] - 1, v[1] - 1, i);
ll val = white - black;
if(!rep) c += val;
else c -= val;
}
ans = min(ans, c + (rep ? (n/i)*(n/i)/2*i*i : ((n/i)*(n/i) + 1)/2*i*i));
}
}
}
cout << ans;
}
int main(){
solve();
return 0;
}
Compilation message
chessboard.cpp: In function 'void solve()':
chessboard.cpp:41:6: warning: unused variable 'a' [-Wunused-variable]
41 | int a = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
272 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
2388 KB |
Output is correct |
2 |
Correct |
21 ms |
1468 KB |
Output is correct |
3 |
Correct |
55 ms |
2396 KB |
Output is correct |
4 |
Correct |
53 ms |
2416 KB |
Output is correct |
5 |
Correct |
72 ms |
2452 KB |
Output is correct |
6 |
Correct |
48 ms |
2376 KB |
Output is correct |
7 |
Correct |
11 ms |
596 KB |
Output is correct |
8 |
Correct |
48 ms |
2368 KB |
Output is correct |
9 |
Correct |
118 ms |
4416 KB |
Output is correct |
10 |
Correct |
67 ms |
2424 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 |
3 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 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 |
3 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
44 ms |
1356 KB |
Output is correct |
17 |
Correct |
88 ms |
4408 KB |
Output is correct |
18 |
Correct |
154 ms |
4408 KB |
Output is correct |
19 |
Correct |
643 ms |
4440 KB |
Output is correct |
20 |
Correct |
738 ms |
4448 KB |
Output is correct |
21 |
Correct |
111 ms |
4412 KB |
Output is correct |
22 |
Correct |
3 ms |
212 KB |
Output is correct |
23 |
Correct |
109 ms |
2520 KB |
Output is correct |
24 |
Correct |
137 ms |
4492 KB |
Output is correct |
25 |
Correct |
21 ms |
848 KB |
Output is correct |
26 |
Correct |
86 ms |
2480 KB |
Output is correct |
27 |
Correct |
139 ms |
4468 KB |
Output is correct |
28 |
Correct |
160 ms |
4408 KB |
Output is correct |
29 |
Correct |
38 ms |
2444 KB |
Output is correct |
30 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
2388 KB |
Output is correct |
2 |
Correct |
21 ms |
1468 KB |
Output is correct |
3 |
Correct |
55 ms |
2396 KB |
Output is correct |
4 |
Correct |
53 ms |
2416 KB |
Output is correct |
5 |
Correct |
72 ms |
2452 KB |
Output is correct |
6 |
Correct |
48 ms |
2376 KB |
Output is correct |
7 |
Correct |
11 ms |
596 KB |
Output is correct |
8 |
Correct |
48 ms |
2368 KB |
Output is correct |
9 |
Correct |
118 ms |
4416 KB |
Output is correct |
10 |
Correct |
67 ms |
2424 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
44 ms |
1356 KB |
Output is correct |
27 |
Correct |
88 ms |
4408 KB |
Output is correct |
28 |
Correct |
154 ms |
4408 KB |
Output is correct |
29 |
Correct |
643 ms |
4440 KB |
Output is correct |
30 |
Correct |
738 ms |
4448 KB |
Output is correct |
31 |
Correct |
111 ms |
4412 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
109 ms |
2520 KB |
Output is correct |
34 |
Correct |
137 ms |
4492 KB |
Output is correct |
35 |
Correct |
21 ms |
848 KB |
Output is correct |
36 |
Correct |
86 ms |
2480 KB |
Output is correct |
37 |
Correct |
139 ms |
4468 KB |
Output is correct |
38 |
Correct |
160 ms |
4408 KB |
Output is correct |
39 |
Correct |
38 ms |
2444 KB |
Output is correct |
40 |
Correct |
5 ms |
468 KB |
Output is correct |
41 |
Correct |
591 ms |
4996 KB |
Output is correct |
42 |
Correct |
176 ms |
4920 KB |
Output is correct |
43 |
Correct |
360 ms |
5036 KB |
Output is correct |
44 |
Correct |
175 ms |
4940 KB |
Output is correct |
45 |
Correct |
131 ms |
4944 KB |
Output is correct |
46 |
Correct |
669 ms |
5028 KB |
Output is correct |
47 |
Correct |
122 ms |
5064 KB |
Output is correct |
48 |
Correct |
267 ms |
5020 KB |
Output is correct |
49 |
Correct |
163 ms |
5008 KB |
Output is correct |
50 |
Execution timed out |
2025 ms |
4920 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
272 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
85 ms |
2388 KB |
Output is correct |
10 |
Correct |
21 ms |
1468 KB |
Output is correct |
11 |
Correct |
55 ms |
2396 KB |
Output is correct |
12 |
Correct |
53 ms |
2416 KB |
Output is correct |
13 |
Correct |
72 ms |
2452 KB |
Output is correct |
14 |
Correct |
48 ms |
2376 KB |
Output is correct |
15 |
Correct |
11 ms |
596 KB |
Output is correct |
16 |
Correct |
48 ms |
2368 KB |
Output is correct |
17 |
Correct |
118 ms |
4416 KB |
Output is correct |
18 |
Correct |
67 ms |
2424 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
44 ms |
1356 KB |
Output is correct |
35 |
Correct |
88 ms |
4408 KB |
Output is correct |
36 |
Correct |
154 ms |
4408 KB |
Output is correct |
37 |
Correct |
643 ms |
4440 KB |
Output is correct |
38 |
Correct |
738 ms |
4448 KB |
Output is correct |
39 |
Correct |
111 ms |
4412 KB |
Output is correct |
40 |
Correct |
3 ms |
212 KB |
Output is correct |
41 |
Correct |
109 ms |
2520 KB |
Output is correct |
42 |
Correct |
137 ms |
4492 KB |
Output is correct |
43 |
Correct |
21 ms |
848 KB |
Output is correct |
44 |
Correct |
86 ms |
2480 KB |
Output is correct |
45 |
Correct |
139 ms |
4468 KB |
Output is correct |
46 |
Correct |
160 ms |
4408 KB |
Output is correct |
47 |
Correct |
38 ms |
2444 KB |
Output is correct |
48 |
Correct |
5 ms |
468 KB |
Output is correct |
49 |
Correct |
591 ms |
4996 KB |
Output is correct |
50 |
Correct |
176 ms |
4920 KB |
Output is correct |
51 |
Correct |
360 ms |
5036 KB |
Output is correct |
52 |
Correct |
175 ms |
4940 KB |
Output is correct |
53 |
Correct |
131 ms |
4944 KB |
Output is correct |
54 |
Correct |
669 ms |
5028 KB |
Output is correct |
55 |
Correct |
122 ms |
5064 KB |
Output is correct |
56 |
Correct |
267 ms |
5020 KB |
Output is correct |
57 |
Correct |
163 ms |
5008 KB |
Output is correct |
58 |
Execution timed out |
2025 ms |
4920 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |