#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
/*
ll pw(ll a, ll b) {
ll ans = 1; while (b) {
while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
ans = (ans * a) % MOD, --b;
} return ans;
}
*/
pair<ll, ll> operator+(pair<ll, ll> a, pair<ll, ll> b) {
return make_pair(a.first + b.first, a.second + b.second);
}
pair<ll, ll> operator-(pair<ll, ll> a, pair<ll, ll> b) {
return make_pair(a.first - b.first, a.second - b.second);
}
pair<ll, ll> get(ll x, ll k) {
ll kx = x / k;
if (kx % 2 == 0)
return make_pair((kx + 1) / 2 * k + x % k, (kx) / 2 * k);
else
return make_pair((kx + 1) / 2 * k, (kx) / 2 * k + x % k);
}
const ll MAXN = 120000;
int n, k;
vector<ll> dv;
pair<ll, ll> go[MAXN];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i < n; ++i) {
if (n % i == 0)
dv.push_back(i);
}
for (int i = 0; i < k; ++i) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1;
for (int it = 0; it < dv.size(); ++it) {
int j = dv[it];
pair<ll, ll> xx = get(x2, j) - get(x1, j);
pair<ll, ll> yy = get(y2, j) - get(y1, j);
go[it] = go[it] + make_pair(xx.first * yy.first + xx.second * yy.second, xx.second * yy.first + xx.first * yy.second);
}
}
ll ans = ll(n) * n;
for (int i = 0; i < dv.size(); ++i) {
ll sd = n / dv[i];
pair<ll, ll> nd = make_pair((sd * sd + 1) / 2 * dv[i] * dv[i], (sd * sd) / 2 * dv[i] * dv[i]);
ans = min(ans, nd.first - go[i].first + go[i].second);
ans = min(ans, nd.second - go[i].second + go[i].first);
}
cout << ans << "\n";
return 0;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int it = 0; it < dv.size(); ++it) {
~~~^~~~~~~~~~~
chessboard.cpp:65:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < dv.size(); ++i) {
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
548 KB |
Output is correct |
6 |
Correct |
3 ms |
548 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
564 KB |
Output is correct |
2 |
Correct |
17 ms |
608 KB |
Output is correct |
3 |
Correct |
31 ms |
724 KB |
Output is correct |
4 |
Correct |
31 ms |
728 KB |
Output is correct |
5 |
Correct |
55 ms |
872 KB |
Output is correct |
6 |
Correct |
19 ms |
872 KB |
Output is correct |
7 |
Correct |
8 ms |
872 KB |
Output is correct |
8 |
Correct |
19 ms |
872 KB |
Output is correct |
9 |
Correct |
45 ms |
872 KB |
Output is correct |
10 |
Correct |
30 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
872 KB |
Output is correct |
2 |
Correct |
3 ms |
872 KB |
Output is correct |
3 |
Correct |
3 ms |
872 KB |
Output is correct |
4 |
Correct |
3 ms |
872 KB |
Output is correct |
5 |
Correct |
4 ms |
872 KB |
Output is correct |
6 |
Correct |
3 ms |
872 KB |
Output is correct |
7 |
Correct |
3 ms |
872 KB |
Output is correct |
8 |
Correct |
3 ms |
872 KB |
Output is correct |
9 |
Correct |
3 ms |
872 KB |
Output is correct |
10 |
Correct |
2 ms |
872 KB |
Output is correct |
11 |
Correct |
2 ms |
872 KB |
Output is correct |
12 |
Correct |
2 ms |
872 KB |
Output is correct |
13 |
Correct |
3 ms |
872 KB |
Output is correct |
14 |
Correct |
3 ms |
872 KB |
Output is correct |
15 |
Correct |
2 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
872 KB |
Output is correct |
2 |
Correct |
3 ms |
872 KB |
Output is correct |
3 |
Correct |
3 ms |
872 KB |
Output is correct |
4 |
Correct |
3 ms |
872 KB |
Output is correct |
5 |
Correct |
4 ms |
872 KB |
Output is correct |
6 |
Correct |
3 ms |
872 KB |
Output is correct |
7 |
Correct |
3 ms |
872 KB |
Output is correct |
8 |
Correct |
3 ms |
872 KB |
Output is correct |
9 |
Correct |
3 ms |
872 KB |
Output is correct |
10 |
Correct |
2 ms |
872 KB |
Output is correct |
11 |
Correct |
2 ms |
872 KB |
Output is correct |
12 |
Correct |
2 ms |
872 KB |
Output is correct |
13 |
Correct |
3 ms |
872 KB |
Output is correct |
14 |
Correct |
3 ms |
872 KB |
Output is correct |
15 |
Correct |
2 ms |
872 KB |
Output is correct |
16 |
Correct |
19 ms |
872 KB |
Output is correct |
17 |
Correct |
38 ms |
872 KB |
Output is correct |
18 |
Correct |
62 ms |
872 KB |
Output is correct |
19 |
Correct |
245 ms |
872 KB |
Output is correct |
20 |
Correct |
311 ms |
872 KB |
Output is correct |
21 |
Correct |
37 ms |
872 KB |
Output is correct |
22 |
Correct |
4 ms |
872 KB |
Output is correct |
23 |
Correct |
46 ms |
872 KB |
Output is correct |
24 |
Correct |
56 ms |
872 KB |
Output is correct |
25 |
Correct |
11 ms |
872 KB |
Output is correct |
26 |
Correct |
51 ms |
872 KB |
Output is correct |
27 |
Correct |
56 ms |
872 KB |
Output is correct |
28 |
Correct |
58 ms |
872 KB |
Output is correct |
29 |
Correct |
15 ms |
872 KB |
Output is correct |
30 |
Correct |
4 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
564 KB |
Output is correct |
2 |
Correct |
17 ms |
608 KB |
Output is correct |
3 |
Correct |
31 ms |
724 KB |
Output is correct |
4 |
Correct |
31 ms |
728 KB |
Output is correct |
5 |
Correct |
55 ms |
872 KB |
Output is correct |
6 |
Correct |
19 ms |
872 KB |
Output is correct |
7 |
Correct |
8 ms |
872 KB |
Output is correct |
8 |
Correct |
19 ms |
872 KB |
Output is correct |
9 |
Correct |
45 ms |
872 KB |
Output is correct |
10 |
Correct |
30 ms |
872 KB |
Output is correct |
11 |
Correct |
3 ms |
872 KB |
Output is correct |
12 |
Correct |
3 ms |
872 KB |
Output is correct |
13 |
Correct |
3 ms |
872 KB |
Output is correct |
14 |
Correct |
3 ms |
872 KB |
Output is correct |
15 |
Correct |
4 ms |
872 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
3 ms |
872 KB |
Output is correct |
18 |
Correct |
3 ms |
872 KB |
Output is correct |
19 |
Correct |
3 ms |
872 KB |
Output is correct |
20 |
Correct |
2 ms |
872 KB |
Output is correct |
21 |
Correct |
2 ms |
872 KB |
Output is correct |
22 |
Correct |
2 ms |
872 KB |
Output is correct |
23 |
Correct |
3 ms |
872 KB |
Output is correct |
24 |
Correct |
3 ms |
872 KB |
Output is correct |
25 |
Correct |
2 ms |
872 KB |
Output is correct |
26 |
Correct |
19 ms |
872 KB |
Output is correct |
27 |
Correct |
38 ms |
872 KB |
Output is correct |
28 |
Correct |
62 ms |
872 KB |
Output is correct |
29 |
Correct |
245 ms |
872 KB |
Output is correct |
30 |
Correct |
311 ms |
872 KB |
Output is correct |
31 |
Correct |
37 ms |
872 KB |
Output is correct |
32 |
Correct |
4 ms |
872 KB |
Output is correct |
33 |
Correct |
46 ms |
872 KB |
Output is correct |
34 |
Correct |
56 ms |
872 KB |
Output is correct |
35 |
Correct |
11 ms |
872 KB |
Output is correct |
36 |
Correct |
51 ms |
872 KB |
Output is correct |
37 |
Correct |
56 ms |
872 KB |
Output is correct |
38 |
Correct |
58 ms |
872 KB |
Output is correct |
39 |
Correct |
15 ms |
872 KB |
Output is correct |
40 |
Correct |
4 ms |
872 KB |
Output is correct |
41 |
Correct |
199 ms |
872 KB |
Output is correct |
42 |
Correct |
66 ms |
872 KB |
Output is correct |
43 |
Correct |
119 ms |
872 KB |
Output is correct |
44 |
Correct |
63 ms |
872 KB |
Output is correct |
45 |
Correct |
55 ms |
872 KB |
Output is correct |
46 |
Correct |
223 ms |
872 KB |
Output is correct |
47 |
Correct |
50 ms |
872 KB |
Output is correct |
48 |
Correct |
103 ms |
872 KB |
Output is correct |
49 |
Correct |
61 ms |
872 KB |
Output is correct |
50 |
Correct |
1085 ms |
872 KB |
Output is correct |
51 |
Correct |
1090 ms |
872 KB |
Output is correct |
52 |
Correct |
1048 ms |
872 KB |
Output is correct |
53 |
Correct |
1060 ms |
872 KB |
Output is correct |
54 |
Correct |
994 ms |
872 KB |
Output is correct |
55 |
Correct |
1182 ms |
872 KB |
Output is correct |
56 |
Correct |
962 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
548 KB |
Output is correct |
6 |
Correct |
3 ms |
548 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
548 KB |
Output is correct |
9 |
Correct |
33 ms |
564 KB |
Output is correct |
10 |
Correct |
17 ms |
608 KB |
Output is correct |
11 |
Correct |
31 ms |
724 KB |
Output is correct |
12 |
Correct |
31 ms |
728 KB |
Output is correct |
13 |
Correct |
55 ms |
872 KB |
Output is correct |
14 |
Correct |
19 ms |
872 KB |
Output is correct |
15 |
Correct |
8 ms |
872 KB |
Output is correct |
16 |
Correct |
19 ms |
872 KB |
Output is correct |
17 |
Correct |
45 ms |
872 KB |
Output is correct |
18 |
Correct |
30 ms |
872 KB |
Output is correct |
19 |
Correct |
3 ms |
872 KB |
Output is correct |
20 |
Correct |
3 ms |
872 KB |
Output is correct |
21 |
Correct |
3 ms |
872 KB |
Output is correct |
22 |
Correct |
3 ms |
872 KB |
Output is correct |
23 |
Correct |
4 ms |
872 KB |
Output is correct |
24 |
Correct |
3 ms |
872 KB |
Output is correct |
25 |
Correct |
3 ms |
872 KB |
Output is correct |
26 |
Correct |
3 ms |
872 KB |
Output is correct |
27 |
Correct |
3 ms |
872 KB |
Output is correct |
28 |
Correct |
2 ms |
872 KB |
Output is correct |
29 |
Correct |
2 ms |
872 KB |
Output is correct |
30 |
Correct |
2 ms |
872 KB |
Output is correct |
31 |
Correct |
3 ms |
872 KB |
Output is correct |
32 |
Correct |
3 ms |
872 KB |
Output is correct |
33 |
Correct |
2 ms |
872 KB |
Output is correct |
34 |
Correct |
19 ms |
872 KB |
Output is correct |
35 |
Correct |
38 ms |
872 KB |
Output is correct |
36 |
Correct |
62 ms |
872 KB |
Output is correct |
37 |
Correct |
245 ms |
872 KB |
Output is correct |
38 |
Correct |
311 ms |
872 KB |
Output is correct |
39 |
Correct |
37 ms |
872 KB |
Output is correct |
40 |
Correct |
4 ms |
872 KB |
Output is correct |
41 |
Correct |
46 ms |
872 KB |
Output is correct |
42 |
Correct |
56 ms |
872 KB |
Output is correct |
43 |
Correct |
11 ms |
872 KB |
Output is correct |
44 |
Correct |
51 ms |
872 KB |
Output is correct |
45 |
Correct |
56 ms |
872 KB |
Output is correct |
46 |
Correct |
58 ms |
872 KB |
Output is correct |
47 |
Correct |
15 ms |
872 KB |
Output is correct |
48 |
Correct |
4 ms |
872 KB |
Output is correct |
49 |
Correct |
199 ms |
872 KB |
Output is correct |
50 |
Correct |
66 ms |
872 KB |
Output is correct |
51 |
Correct |
119 ms |
872 KB |
Output is correct |
52 |
Correct |
63 ms |
872 KB |
Output is correct |
53 |
Correct |
55 ms |
872 KB |
Output is correct |
54 |
Correct |
223 ms |
872 KB |
Output is correct |
55 |
Correct |
50 ms |
872 KB |
Output is correct |
56 |
Correct |
103 ms |
872 KB |
Output is correct |
57 |
Correct |
61 ms |
872 KB |
Output is correct |
58 |
Correct |
1085 ms |
872 KB |
Output is correct |
59 |
Correct |
1090 ms |
872 KB |
Output is correct |
60 |
Correct |
1048 ms |
872 KB |
Output is correct |
61 |
Correct |
1060 ms |
872 KB |
Output is correct |
62 |
Correct |
994 ms |
872 KB |
Output is correct |
63 |
Correct |
1182 ms |
872 KB |
Output is correct |
64 |
Correct |
962 ms |
872 KB |
Output is correct |
65 |
Correct |
3 ms |
872 KB |
Output is correct |
66 |
Correct |
2 ms |
872 KB |
Output is correct |
67 |
Correct |
1096 ms |
872 KB |
Output is correct |
68 |
Correct |
1113 ms |
872 KB |
Output is correct |
69 |
Correct |
967 ms |
872 KB |
Output is correct |
70 |
Correct |
1163 ms |
872 KB |
Output is correct |
71 |
Correct |
1049 ms |
872 KB |
Output is correct |
72 |
Correct |
1059 ms |
908 KB |
Output is correct |
73 |
Correct |
958 ms |
908 KB |
Output is correct |
74 |
Correct |
1095 ms |
908 KB |
Output is correct |
75 |
Correct |
1029 ms |
908 KB |
Output is correct |
76 |
Correct |
1145 ms |
908 KB |
Output is correct |
77 |
Correct |
182 ms |
908 KB |
Output is correct |
78 |
Correct |
65 ms |
908 KB |
Output is correct |
79 |
Correct |
125 ms |
908 KB |
Output is correct |
80 |
Correct |
181 ms |
908 KB |
Output is correct |
81 |
Correct |
118 ms |
908 KB |
Output is correct |
82 |
Correct |
107 ms |
908 KB |
Output is correct |
83 |
Correct |
87 ms |
908 KB |
Output is correct |
84 |
Correct |
644 ms |
908 KB |
Output is correct |
85 |
Correct |
1151 ms |
908 KB |
Output is correct |
86 |
Correct |
3 ms |
908 KB |
Output is correct |
87 |
Correct |
3 ms |
908 KB |
Output is correct |
88 |
Correct |
1221 ms |
908 KB |
Output is correct |
89 |
Correct |
215 ms |
908 KB |
Output is correct |
90 |
Correct |
5 ms |
908 KB |
Output is correct |