/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
LL n, k, best = mod * mod;
pair<LL, LL> c1[100005], c2[100005];
vector<LL> d;
LL check(LL d)
{
LL r = (n*n) / (d*d) / 2 * (d*d);
if (((n*n) / (d*d)) % 2 == 1)
r += d * d;
vector<int> prk(n+5,0), prz(n + 5,0);
for (int i = 1; i <= n; i++)
{
prk[i] = prk[i - 1];
if (((i-1) / d) % 2 == 0)
prk[i]++;
prz[i] = i - prk[i];
}
for (LL i = 0; i < k; i++)
{
LL zx = prz[c2[i].first] - prz[c1[i].first - 1], zy = prz[c2[i].second] - prz[c1[i].second - 1];
LL kx = prk[c2[i].first] - prk[c1[i].first - 1], ky = prk[c2[i].second] - prk[c1[i].second - 1];
r -= zx * zy;
r -= kx * ky;
r += kx * zy;
r += zx * ky;
}
return r;
}
int main()
{
cin >> n >> k;
for (LL i = 1; i <= n / 2; i++)
if (n%i == 0)
d.PB(i);
for (LL i = 0; i < k; i++)
{
cin >> c1[i].first >> c1[i].second >> c2[i].first >> c2[i].second;
}
for (LL i = 0; i < d.size(); i++)
{
LL ans = check(d[i]);
best = min(best, min(n*n - ans, ans));
}
cout << best << endl;
return 0;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (LL i = 0; i < d.size(); i++)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
4220 KB |
Output is correct |
2 |
Correct |
20 ms |
1272 KB |
Output is correct |
3 |
Correct |
68 ms |
3192 KB |
Output is correct |
4 |
Correct |
46 ms |
2552 KB |
Output is correct |
5 |
Correct |
68 ms |
3828 KB |
Output is correct |
6 |
Correct |
43 ms |
2556 KB |
Output is correct |
7 |
Correct |
11 ms |
896 KB |
Output is correct |
8 |
Correct |
45 ms |
2680 KB |
Output is correct |
9 |
Correct |
109 ms |
5468 KB |
Output is correct |
10 |
Correct |
63 ms |
3312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
284 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
372 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
284 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
372 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
29 ms |
1664 KB |
Output is correct |
17 |
Correct |
87 ms |
4344 KB |
Output is correct |
18 |
Correct |
120 ms |
4984 KB |
Output is correct |
19 |
Correct |
154 ms |
4472 KB |
Output is correct |
20 |
Correct |
108 ms |
5120 KB |
Output is correct |
21 |
Correct |
79 ms |
4088 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
59 ms |
2324 KB |
Output is correct |
24 |
Correct |
116 ms |
4628 KB |
Output is correct |
25 |
Correct |
11 ms |
768 KB |
Output is correct |
26 |
Correct |
53 ms |
2936 KB |
Output is correct |
27 |
Correct |
69 ms |
3576 KB |
Output is correct |
28 |
Correct |
118 ms |
4856 KB |
Output is correct |
29 |
Correct |
37 ms |
1912 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
4220 KB |
Output is correct |
2 |
Correct |
20 ms |
1272 KB |
Output is correct |
3 |
Correct |
68 ms |
3192 KB |
Output is correct |
4 |
Correct |
46 ms |
2552 KB |
Output is correct |
5 |
Correct |
68 ms |
3828 KB |
Output is correct |
6 |
Correct |
43 ms |
2556 KB |
Output is correct |
7 |
Correct |
11 ms |
896 KB |
Output is correct |
8 |
Correct |
45 ms |
2680 KB |
Output is correct |
9 |
Correct |
109 ms |
5468 KB |
Output is correct |
10 |
Correct |
63 ms |
3312 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
284 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
372 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
29 ms |
1664 KB |
Output is correct |
27 |
Correct |
87 ms |
4344 KB |
Output is correct |
28 |
Correct |
120 ms |
4984 KB |
Output is correct |
29 |
Correct |
154 ms |
4472 KB |
Output is correct |
30 |
Correct |
108 ms |
5120 KB |
Output is correct |
31 |
Correct |
79 ms |
4088 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
59 ms |
2324 KB |
Output is correct |
34 |
Correct |
116 ms |
4628 KB |
Output is correct |
35 |
Correct |
11 ms |
768 KB |
Output is correct |
36 |
Correct |
53 ms |
2936 KB |
Output is correct |
37 |
Correct |
69 ms |
3576 KB |
Output is correct |
38 |
Correct |
118 ms |
4856 KB |
Output is correct |
39 |
Correct |
37 ms |
1912 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
174 ms |
5788 KB |
Output is correct |
42 |
Correct |
216 ms |
6392 KB |
Output is correct |
43 |
Correct |
152 ms |
5752 KB |
Output is correct |
44 |
Correct |
145 ms |
6180 KB |
Output is correct |
45 |
Correct |
121 ms |
6520 KB |
Output is correct |
46 |
Correct |
200 ms |
6448 KB |
Output is correct |
47 |
Correct |
104 ms |
5880 KB |
Output is correct |
48 |
Correct |
146 ms |
5952 KB |
Output is correct |
49 |
Correct |
113 ms |
5724 KB |
Output is correct |
50 |
Correct |
534 ms |
6132 KB |
Output is correct |
51 |
Correct |
589 ms |
6668 KB |
Output is correct |
52 |
Correct |
543 ms |
6248 KB |
Output is correct |
53 |
Correct |
531 ms |
6352 KB |
Output is correct |
54 |
Correct |
412 ms |
6056 KB |
Output is correct |
55 |
Correct |
520 ms |
6656 KB |
Output is correct |
56 |
Correct |
474 ms |
5932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
84 ms |
4220 KB |
Output is correct |
10 |
Correct |
20 ms |
1272 KB |
Output is correct |
11 |
Correct |
68 ms |
3192 KB |
Output is correct |
12 |
Correct |
46 ms |
2552 KB |
Output is correct |
13 |
Correct |
68 ms |
3828 KB |
Output is correct |
14 |
Correct |
43 ms |
2556 KB |
Output is correct |
15 |
Correct |
11 ms |
896 KB |
Output is correct |
16 |
Correct |
45 ms |
2680 KB |
Output is correct |
17 |
Correct |
109 ms |
5468 KB |
Output is correct |
18 |
Correct |
63 ms |
3312 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
284 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
372 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
29 ms |
1664 KB |
Output is correct |
35 |
Correct |
87 ms |
4344 KB |
Output is correct |
36 |
Correct |
120 ms |
4984 KB |
Output is correct |
37 |
Correct |
154 ms |
4472 KB |
Output is correct |
38 |
Correct |
108 ms |
5120 KB |
Output is correct |
39 |
Correct |
79 ms |
4088 KB |
Output is correct |
40 |
Correct |
3 ms |
384 KB |
Output is correct |
41 |
Correct |
59 ms |
2324 KB |
Output is correct |
42 |
Correct |
116 ms |
4628 KB |
Output is correct |
43 |
Correct |
11 ms |
768 KB |
Output is correct |
44 |
Correct |
53 ms |
2936 KB |
Output is correct |
45 |
Correct |
69 ms |
3576 KB |
Output is correct |
46 |
Correct |
118 ms |
4856 KB |
Output is correct |
47 |
Correct |
37 ms |
1912 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
174 ms |
5788 KB |
Output is correct |
50 |
Correct |
216 ms |
6392 KB |
Output is correct |
51 |
Correct |
152 ms |
5752 KB |
Output is correct |
52 |
Correct |
145 ms |
6180 KB |
Output is correct |
53 |
Correct |
121 ms |
6520 KB |
Output is correct |
54 |
Correct |
200 ms |
6448 KB |
Output is correct |
55 |
Correct |
104 ms |
5880 KB |
Output is correct |
56 |
Correct |
146 ms |
5952 KB |
Output is correct |
57 |
Correct |
113 ms |
5724 KB |
Output is correct |
58 |
Correct |
534 ms |
6132 KB |
Output is correct |
59 |
Correct |
589 ms |
6668 KB |
Output is correct |
60 |
Correct |
543 ms |
6248 KB |
Output is correct |
61 |
Correct |
531 ms |
6352 KB |
Output is correct |
62 |
Correct |
412 ms |
6056 KB |
Output is correct |
63 |
Correct |
520 ms |
6656 KB |
Output is correct |
64 |
Correct |
474 ms |
5932 KB |
Output is correct |
65 |
Correct |
2 ms |
384 KB |
Output is correct |
66 |
Correct |
2 ms |
384 KB |
Output is correct |
67 |
Correct |
562 ms |
6352 KB |
Output is correct |
68 |
Correct |
583 ms |
6504 KB |
Output is correct |
69 |
Correct |
552 ms |
5952 KB |
Output is correct |
70 |
Correct |
429 ms |
6080 KB |
Output is correct |
71 |
Correct |
455 ms |
6120 KB |
Output is correct |
72 |
Correct |
502 ms |
5964 KB |
Output is correct |
73 |
Correct |
494 ms |
5788 KB |
Output is correct |
74 |
Correct |
531 ms |
6272 KB |
Output is correct |
75 |
Correct |
498 ms |
6088 KB |
Output is correct |
76 |
Correct |
722 ms |
6296 KB |
Output is correct |
77 |
Correct |
203 ms |
6624 KB |
Output is correct |
78 |
Correct |
142 ms |
6008 KB |
Output is correct |
79 |
Correct |
179 ms |
5948 KB |
Output is correct |
80 |
Correct |
196 ms |
6124 KB |
Output is correct |
81 |
Correct |
154 ms |
5736 KB |
Output is correct |
82 |
Correct |
137 ms |
6324 KB |
Output is correct |
83 |
Correct |
130 ms |
6056 KB |
Output is correct |
84 |
Correct |
358 ms |
6512 KB |
Output is correct |
85 |
Correct |
566 ms |
6528 KB |
Output is correct |
86 |
Correct |
162 ms |
1148 KB |
Output is correct |
87 |
Correct |
227 ms |
1096 KB |
Output is correct |
88 |
Correct |
605 ms |
6776 KB |
Output is correct |
89 |
Correct |
217 ms |
2184 KB |
Output is correct |
90 |
Correct |
154 ms |
1040 KB |
Output is correct |