Submission #377602

# Submission time Handle Problem Language Result Execution time Memory
377602 2021-03-14T11:13:07 Z SeDunion Chessboard (IZhO18_chessboard) C++17
100 / 100
894 ms 4460 KB
#include<bits/stdc++.h>
#ifndef LOCAL
#define cerr if(false)cerr
#endif // LOCAL
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

#define y1 slkdjflkjsdlfkjlskjfjklkdjslfjslkdjflkjlsdkjflkjslkdjflkdslfkjsldklkjsdjfntnfj
#define y0 alsjdljrktnmndfdfgjhkjhdkfjgbtnmbmfhkjgdkjfhkjxhkjhgtgbhhdjbhjhtdbjbhjhtbhbgbb

int x0[N], y0[N], x1[N], y1[N], n, k;

ll cnt(int d, int x, int y) {
	if (x < 0 || y < 0) return 0;
	int X = x / d, Y = y / d;
	if (0) {
		ll cur = 0;
		for (int i = 0 ; i < X * d ; ++ i) {
			for (int j = 0 ; j < Y * d ; ++ j) {
				if ((i / d + j / d) % 2 == 0) cur++;
			}
		}
		return cur;
	}
	cerr << d << " : " << x << " " << y << " " << X << " " << Y << endl;
	ll cur = ((X * 1ll * Y + 1) / 2) * d * d;
	ll Xc = Y % 2 == 1 ? X / 2 : (X + 1) / 2;
	ll Yc = X % 2 == 1 ? Y / 2 : (Y + 1) / 2;
	cur += Xc * d * (y - Y * d + 1);
	cur += Yc * d * (x - X * d + 1);
	if ((X + Y) % 2 == 0)
		cur += (x - X * d + 1) * 1ll * (y - Y * d + 1);
	return cur;
}

ll solve(int d) {
	ll cur = cnt(d, n-1, n-1);
	for (int i = 0 ; i < k ; ++ i) {
		ll black = cnt(d, x1[i], y1[i]) - cnt(d, x0[i] - 1, y1[i]) - cnt(d, x1[i], y0[i] - 1) + cnt(d, x0[i] - 1, y0[i] - 1);
		ll area = (y1[i] - y0[i] + 1) * 1ll * (x1[i] - x0[i] + 1);
		//cerr << d << " " << black << " " << area << " d/black/area\n";
		cur += area - black * 2;
	}
	return cur;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 0 ; i < k ; ++ i) {
		cin >> x0[i] >> y0[i] >> x1[i] >> y1[i];
		x0[i]--, y0[i]--, x1[i]--, y1[i]--;
	}
	ll ans = n * 1ll * n;
	for (int d = 1 ; d < n ; ++ d) {
		if (n % d == 0) {
			for (int i = 0 ; i < n ; ++ i) {
				for (int j = 0 ; j < n ; ++ j) {
					if ((i / d + j / d) % 2 == 0) cerr << "X";
					else cerr << ".";
				}
				cerr << "\n";
			}
			cerr << "\n";
			ll cur = solve(d);
			ans = min(ans, min(cur, n * 1ll * n - cur));
		}
	}
	cout << ans;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:61:9: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   61 |      if ((i / d + j / d) % 2 == 0) cerr << "X";
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1516 KB Output is correct
2 Correct 8 ms 748 KB Output is correct
3 Correct 17 ms 1004 KB Output is correct
4 Correct 19 ms 1132 KB Output is correct
5 Correct 25 ms 1260 KB Output is correct
6 Correct 17 ms 876 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 17 ms 1024 KB Output is correct
9 Correct 39 ms 1900 KB Output is correct
10 Correct 27 ms 1132 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 14 ms 748 KB Output is correct
17 Correct 32 ms 3052 KB Output is correct
18 Correct 50 ms 3564 KB Output is correct
19 Correct 174 ms 3308 KB Output is correct
20 Correct 194 ms 3564 KB Output is correct
21 Correct 32 ms 2924 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 32 ms 1772 KB Output is correct
24 Correct 46 ms 3212 KB Output is correct
25 Correct 8 ms 620 KB Output is correct
26 Correct 35 ms 2156 KB Output is correct
27 Correct 43 ms 2540 KB Output is correct
28 Correct 49 ms 3436 KB Output is correct
29 Correct 13 ms 1388 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1516 KB Output is correct
2 Correct 8 ms 748 KB Output is correct
3 Correct 17 ms 1004 KB Output is correct
4 Correct 19 ms 1132 KB Output is correct
5 Correct 25 ms 1260 KB Output is correct
6 Correct 17 ms 876 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 17 ms 1024 KB Output is correct
9 Correct 39 ms 1900 KB Output is correct
10 Correct 27 ms 1132 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 1 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 384 KB Output is correct
22 Correct 1 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 14 ms 748 KB Output is correct
27 Correct 32 ms 3052 KB Output is correct
28 Correct 50 ms 3564 KB Output is correct
29 Correct 174 ms 3308 KB Output is correct
30 Correct 194 ms 3564 KB Output is correct
31 Correct 32 ms 2924 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 32 ms 1772 KB Output is correct
34 Correct 46 ms 3212 KB Output is correct
35 Correct 8 ms 620 KB Output is correct
36 Correct 35 ms 2156 KB Output is correct
37 Correct 43 ms 2540 KB Output is correct
38 Correct 49 ms 3436 KB Output is correct
39 Correct 13 ms 1388 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 155 ms 3820 KB Output is correct
42 Correct 54 ms 4076 KB Output is correct
43 Correct 91 ms 3692 KB Output is correct
44 Correct 53 ms 3948 KB Output is correct
45 Correct 55 ms 4204 KB Output is correct
46 Correct 191 ms 4204 KB Output is correct
47 Correct 39 ms 3820 KB Output is correct
48 Correct 76 ms 3820 KB Output is correct
49 Correct 52 ms 3820 KB Output is correct
50 Correct 775 ms 3948 KB Output is correct
51 Correct 832 ms 4332 KB Output is correct
52 Correct 776 ms 3948 KB Output is correct
53 Correct 894 ms 4332 KB Output is correct
54 Correct 767 ms 4076 KB Output is correct
55 Correct 867 ms 4460 KB Output is correct
56 Correct 737 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 27 ms 1516 KB Output is correct
10 Correct 8 ms 748 KB Output is correct
11 Correct 17 ms 1004 KB Output is correct
12 Correct 19 ms 1132 KB Output is correct
13 Correct 25 ms 1260 KB Output is correct
14 Correct 17 ms 876 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 17 ms 1024 KB Output is correct
17 Correct 39 ms 1900 KB Output is correct
18 Correct 27 ms 1132 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 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 384 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 14 ms 748 KB Output is correct
35 Correct 32 ms 3052 KB Output is correct
36 Correct 50 ms 3564 KB Output is correct
37 Correct 174 ms 3308 KB Output is correct
38 Correct 194 ms 3564 KB Output is correct
39 Correct 32 ms 2924 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 32 ms 1772 KB Output is correct
42 Correct 46 ms 3212 KB Output is correct
43 Correct 8 ms 620 KB Output is correct
44 Correct 35 ms 2156 KB Output is correct
45 Correct 43 ms 2540 KB Output is correct
46 Correct 49 ms 3436 KB Output is correct
47 Correct 13 ms 1388 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 155 ms 3820 KB Output is correct
50 Correct 54 ms 4076 KB Output is correct
51 Correct 91 ms 3692 KB Output is correct
52 Correct 53 ms 3948 KB Output is correct
53 Correct 55 ms 4204 KB Output is correct
54 Correct 191 ms 4204 KB Output is correct
55 Correct 39 ms 3820 KB Output is correct
56 Correct 76 ms 3820 KB Output is correct
57 Correct 52 ms 3820 KB Output is correct
58 Correct 775 ms 3948 KB Output is correct
59 Correct 832 ms 4332 KB Output is correct
60 Correct 776 ms 3948 KB Output is correct
61 Correct 894 ms 4332 KB Output is correct
62 Correct 767 ms 4076 KB Output is correct
63 Correct 867 ms 4460 KB Output is correct
64 Correct 737 ms 3948 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 824 ms 4204 KB Output is correct
68 Correct 836 ms 4204 KB Output is correct
69 Correct 717 ms 3564 KB Output is correct
70 Correct 784 ms 4076 KB Output is correct
71 Correct 784 ms 3960 KB Output is correct
72 Correct 753 ms 4096 KB Output is correct
73 Correct 754 ms 3820 KB Output is correct
74 Correct 808 ms 4140 KB Output is correct
75 Correct 774 ms 3948 KB Output is correct
76 Correct 825 ms 4296 KB Output is correct
77 Correct 139 ms 4460 KB Output is correct
78 Correct 54 ms 3948 KB Output is correct
79 Correct 99 ms 3692 KB Output is correct
80 Correct 109 ms 3948 KB Output is correct
81 Correct 92 ms 3684 KB Output is correct
82 Correct 84 ms 4076 KB Output is correct
83 Correct 67 ms 3820 KB Output is correct
84 Correct 497 ms 4332 KB Output is correct
85 Correct 862 ms 4304 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 880 ms 4460 KB Output is correct
89 Correct 171 ms 1260 KB Output is correct
90 Correct 1 ms 364 KB Output is correct