#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1e5 + 7;
const ll oo = 1e18;
array<int, 4> a[N];
signed main()
{
IO_OP;
int n, k;
cin >> n >> k;
for(int i = 0; i < k; i++) {
for(int j = 0; j < 4; j++)
cin >> a[i][j], a[i][j]--;
}
ll ans = oo;
auto go = [&] (int b) {
int m = n / b;
ll white = (ll) m * m / 2 * b * b, black = (ll) n * n - white;
ll wb = 0;
auto solve = [&] (int x, int y) {
if(x < 0 || y < 0) return 0LL;
int l = (x + 1) % (2 * b), r = (y + 1) % (2 * b);
ll W = 0, B = 0;
B += (ll) min(l, b) * min(r, b);
B += (ll) max(0, l - b) * max(0, r - b);
W += (ll) min(l, b) * max(0, r - b);
W += (ll) max(0, l - b) * min(r, b);
if((x / (2 * b) * (2 * b) / b + y / (2 * b) * (2 * b) / b) & 1)
swap(W, B);
return W - B;
};
for(int i = 0; i < k; i++) {
wb += solve(a[i][2], a[i][3]) - solve(a[i][0] - 1, a[i][3]) - solve(a[i][2], a[i][1] - 1) + solve(a[i][0] - 1, a[i][1] - 1);
}
return black + wb;
};
for(int i = 1; i < n; i++) {
if(n % i == 0) {
ll t = go(i);
t = min(t, (ll) n * n - t);
ans = min(ans, t);
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1388 KB |
Output is correct |
2 |
Correct |
9 ms |
748 KB |
Output is correct |
3 |
Correct |
23 ms |
1004 KB |
Output is correct |
4 |
Correct |
25 ms |
1132 KB |
Output is correct |
5 |
Correct |
33 ms |
1260 KB |
Output is correct |
6 |
Correct |
20 ms |
1004 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
20 ms |
1004 KB |
Output is correct |
9 |
Correct |
53 ms |
1900 KB |
Output is correct |
10 |
Correct |
29 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
21 ms |
876 KB |
Output is correct |
17 |
Correct |
40 ms |
1772 KB |
Output is correct |
18 |
Correct |
75 ms |
2036 KB |
Output is correct |
19 |
Correct |
371 ms |
1772 KB |
Output is correct |
20 |
Correct |
409 ms |
2156 KB |
Output is correct |
21 |
Correct |
38 ms |
1644 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
56 ms |
1152 KB |
Output is correct |
24 |
Correct |
68 ms |
1900 KB |
Output is correct |
25 |
Correct |
13 ms |
620 KB |
Output is correct |
26 |
Correct |
43 ms |
1376 KB |
Output is correct |
27 |
Correct |
71 ms |
1516 KB |
Output is correct |
28 |
Correct |
72 ms |
1900 KB |
Output is correct |
29 |
Correct |
16 ms |
1004 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1388 KB |
Output is correct |
2 |
Correct |
9 ms |
748 KB |
Output is correct |
3 |
Correct |
23 ms |
1004 KB |
Output is correct |
4 |
Correct |
25 ms |
1132 KB |
Output is correct |
5 |
Correct |
33 ms |
1260 KB |
Output is correct |
6 |
Correct |
20 ms |
1004 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
20 ms |
1004 KB |
Output is correct |
9 |
Correct |
53 ms |
1900 KB |
Output is correct |
10 |
Correct |
29 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
21 ms |
876 KB |
Output is correct |
27 |
Correct |
40 ms |
1772 KB |
Output is correct |
28 |
Correct |
75 ms |
2036 KB |
Output is correct |
29 |
Correct |
371 ms |
1772 KB |
Output is correct |
30 |
Correct |
409 ms |
2156 KB |
Output is correct |
31 |
Correct |
38 ms |
1644 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
56 ms |
1152 KB |
Output is correct |
34 |
Correct |
68 ms |
1900 KB |
Output is correct |
35 |
Correct |
13 ms |
620 KB |
Output is correct |
36 |
Correct |
43 ms |
1376 KB |
Output is correct |
37 |
Correct |
71 ms |
1516 KB |
Output is correct |
38 |
Correct |
72 ms |
1900 KB |
Output is correct |
39 |
Correct |
16 ms |
1004 KB |
Output is correct |
40 |
Correct |
3 ms |
364 KB |
Output is correct |
41 |
Correct |
334 ms |
1784 KB |
Output is correct |
42 |
Correct |
82 ms |
1900 KB |
Output is correct |
43 |
Correct |
179 ms |
1792 KB |
Output is correct |
44 |
Correct |
90 ms |
1912 KB |
Output is correct |
45 |
Correct |
54 ms |
1900 KB |
Output is correct |
46 |
Correct |
371 ms |
1900 KB |
Output is correct |
47 |
Correct |
48 ms |
1920 KB |
Output is correct |
48 |
Correct |
130 ms |
1900 KB |
Output is correct |
49 |
Correct |
76 ms |
1772 KB |
Output is correct |
50 |
Correct |
1833 ms |
1908 KB |
Output is correct |
51 |
Correct |
1947 ms |
2000 KB |
Output is correct |
52 |
Correct |
1819 ms |
1900 KB |
Output is correct |
53 |
Correct |
1940 ms |
1992 KB |
Output is correct |
54 |
Correct |
1802 ms |
1880 KB |
Output is correct |
55 |
Execution timed out |
2008 ms |
2052 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
35 ms |
1388 KB |
Output is correct |
10 |
Correct |
9 ms |
748 KB |
Output is correct |
11 |
Correct |
23 ms |
1004 KB |
Output is correct |
12 |
Correct |
25 ms |
1132 KB |
Output is correct |
13 |
Correct |
33 ms |
1260 KB |
Output is correct |
14 |
Correct |
20 ms |
1004 KB |
Output is correct |
15 |
Correct |
5 ms |
492 KB |
Output is correct |
16 |
Correct |
20 ms |
1004 KB |
Output is correct |
17 |
Correct |
53 ms |
1900 KB |
Output is correct |
18 |
Correct |
29 ms |
1260 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
21 ms |
876 KB |
Output is correct |
35 |
Correct |
40 ms |
1772 KB |
Output is correct |
36 |
Correct |
75 ms |
2036 KB |
Output is correct |
37 |
Correct |
371 ms |
1772 KB |
Output is correct |
38 |
Correct |
409 ms |
2156 KB |
Output is correct |
39 |
Correct |
38 ms |
1644 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
56 ms |
1152 KB |
Output is correct |
42 |
Correct |
68 ms |
1900 KB |
Output is correct |
43 |
Correct |
13 ms |
620 KB |
Output is correct |
44 |
Correct |
43 ms |
1376 KB |
Output is correct |
45 |
Correct |
71 ms |
1516 KB |
Output is correct |
46 |
Correct |
72 ms |
1900 KB |
Output is correct |
47 |
Correct |
16 ms |
1004 KB |
Output is correct |
48 |
Correct |
3 ms |
364 KB |
Output is correct |
49 |
Correct |
334 ms |
1784 KB |
Output is correct |
50 |
Correct |
82 ms |
1900 KB |
Output is correct |
51 |
Correct |
179 ms |
1792 KB |
Output is correct |
52 |
Correct |
90 ms |
1912 KB |
Output is correct |
53 |
Correct |
54 ms |
1900 KB |
Output is correct |
54 |
Correct |
371 ms |
1900 KB |
Output is correct |
55 |
Correct |
48 ms |
1920 KB |
Output is correct |
56 |
Correct |
130 ms |
1900 KB |
Output is correct |
57 |
Correct |
76 ms |
1772 KB |
Output is correct |
58 |
Correct |
1833 ms |
1908 KB |
Output is correct |
59 |
Correct |
1947 ms |
2000 KB |
Output is correct |
60 |
Correct |
1819 ms |
1900 KB |
Output is correct |
61 |
Correct |
1940 ms |
1992 KB |
Output is correct |
62 |
Correct |
1802 ms |
1880 KB |
Output is correct |
63 |
Execution timed out |
2008 ms |
2052 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |