Submission #501866

# Submission time Handle Problem Language Result Execution time Memory
501866 2022-01-04T17:35:20 Z NachoLibre Chessboard (IZhO18_chessboard) C++17
100 / 100
839 ms 4488 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

ll Fw(ll n, ll m, int w) {
	return n / w * m / w / 2 * w * w;
}
ll Fb(ll n, ll m, int w) {
	return n * m - Fw(n, m, w);
}
ll B(ll n, ll m, int w, int x = 0, int y = 0) {
	if(x / w + y / w & 1)
	return Fb(n, m, w);
	return Fw(n, m, w);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifdef wambule
	freopen("untitledfile.txt", "r", stdin);
	#endif
	ll n;
	int k;
	cin >> n >> k;
	vector<array<int, 4>> v;
	for(int i = 0; i < k; ++i) {
		array<int, 4> x;
		cin >> x[0] >> x[2] >> x[1] >> x[3];
		x[0] -= 1; x[1] -= 1;
		x[2] -= 1; x[3] -= 1;
		v.push_back(x);
	}
	vector<int> d{1};
	for(int i = 2; i * i <= n; ++i) {
		if(n % i == 0) {
			d.push_back(i);
			if(i * i ^ n) d.push_back(n / i);
		}
	}
	ll fp = n * n;
	for(int w : d) {
		ll ap = B(n, n, w);
		// cout << w << " -0- " << ap << endl;
		for(auto y : v) {
			array<int, 4> x;
			x[0] = y[0] / w * w;
			x[2] = y[2] / w * w;
			x[1] = y[1] / w * w + w - 1;
			x[3] = y[3] / w * w + w - 1;
			ll xn = x[1] - x[0] + 1;
			ll xm = x[3] - x[2] + 1;
			ll tp = B(xn, xm, w, x[0], x[2]);

			tp -= B(w, xm, w, x[0], x[2]) / w * (y[0] - x[0]);
			tp -= B(w, xm, w, x[1] + 1 - w, x[2]) / w * (x[1] - y[1]);
			tp -= B(xn, w, w, x[0], x[2]) / w * (y[2] - x[2]);
			tp -= B(xn, w, w, x[0], x[3] + 1 - w) / w * (x[3] - y[3]);

			tp += B(w, w, w, x[0], x[2]) / w / w * (y[2] - x[2]) * (y[0] - x[0]);
			tp += B(w, w, w, x[0], x[3] + 1 - w) / w / w * (x[3] - y[3]) * (y[0] - x[0]);
			tp += B(w, w, w, x[1] + 1 - w, x[3] + 1 - w) / w / w * (x[3] - y[3]) * (x[1] - y[1]);
			tp += B(w, w, w, x[1] + 1 - w, x[2]) / w / w * (y[2] - x[2]) * (x[1] - y[1]);

			ap -= tp;
			ap += 1ll * (y[1] - y[0] + 1) * (y[3] - y[2] + 1) - tp;

			// cout << w << "\n";
			// cout << y[0] << " " << y[1] << " " << y[2] << " " << y[3] << "\n";
			// cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << "\n";
			// cout << tp << "\n\n";
		}
		// cout << w << " -1- " << ap << endl;
		fp = min(fp, min(ap, n * n - ap));
	}
	cout << fp << endl;
	return 0;
}

Compilation message

chessboard.cpp: In function 'long long int B(long long int, long long int, int, int, int)':
chessboard.cpp:15:11: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   15 |  if(x / w + y / w & 1)
      |     ~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2880 KB Output is correct
2 Correct 7 ms 1220 KB Output is correct
3 Correct 15 ms 2412 KB Output is correct
4 Correct 16 ms 2240 KB Output is correct
5 Correct 21 ms 2516 KB Output is correct
6 Correct 15 ms 2212 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 14 ms 2264 KB Output is correct
9 Correct 37 ms 4028 KB Output is correct
10 Correct 21 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 15 ms 1300 KB Output is correct
17 Correct 27 ms 3844 KB Output is correct
18 Correct 42 ms 3632 KB Output is correct
19 Correct 163 ms 3708 KB Output is correct
20 Correct 181 ms 3720 KB Output is correct
21 Correct 25 ms 3648 KB Output is correct
22 Correct 1 ms 292 KB Output is correct
23 Correct 27 ms 2108 KB Output is correct
24 Correct 38 ms 3700 KB Output is correct
25 Correct 6 ms 832 KB Output is correct
26 Correct 25 ms 2200 KB Output is correct
27 Correct 44 ms 3592 KB Output is correct
28 Correct 43 ms 3636 KB Output is correct
29 Correct 12 ms 2000 KB Output is correct
30 Correct 2 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2880 KB Output is correct
2 Correct 7 ms 1220 KB Output is correct
3 Correct 15 ms 2412 KB Output is correct
4 Correct 16 ms 2240 KB Output is correct
5 Correct 21 ms 2516 KB Output is correct
6 Correct 15 ms 2212 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 14 ms 2264 KB Output is correct
9 Correct 37 ms 4028 KB Output is correct
10 Correct 21 ms 2388 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 15 ms 1300 KB Output is correct
27 Correct 27 ms 3844 KB Output is correct
28 Correct 42 ms 3632 KB Output is correct
29 Correct 163 ms 3708 KB Output is correct
30 Correct 181 ms 3720 KB Output is correct
31 Correct 25 ms 3648 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 27 ms 2108 KB Output is correct
34 Correct 38 ms 3700 KB Output is correct
35 Correct 6 ms 832 KB Output is correct
36 Correct 25 ms 2200 KB Output is correct
37 Correct 44 ms 3592 KB Output is correct
38 Correct 43 ms 3636 KB Output is correct
39 Correct 12 ms 2000 KB Output is correct
40 Correct 2 ms 368 KB Output is correct
41 Correct 147 ms 4252 KB Output is correct
42 Correct 47 ms 4244 KB Output is correct
43 Correct 81 ms 4152 KB Output is correct
44 Correct 45 ms 4160 KB Output is correct
45 Correct 35 ms 4288 KB Output is correct
46 Correct 169 ms 4244 KB Output is correct
47 Correct 32 ms 4200 KB Output is correct
48 Correct 64 ms 4156 KB Output is correct
49 Correct 46 ms 4188 KB Output is correct
50 Correct 750 ms 4232 KB Output is correct
51 Correct 814 ms 4404 KB Output is correct
52 Correct 754 ms 4196 KB Output is correct
53 Correct 786 ms 4240 KB Output is correct
54 Correct 714 ms 4276 KB Output is correct
55 Correct 815 ms 4488 KB Output is correct
56 Correct 733 ms 4232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 24 ms 2880 KB Output is correct
10 Correct 7 ms 1220 KB Output is correct
11 Correct 15 ms 2412 KB Output is correct
12 Correct 16 ms 2240 KB Output is correct
13 Correct 21 ms 2516 KB Output is correct
14 Correct 15 ms 2212 KB Output is correct
15 Correct 3 ms 716 KB Output is correct
16 Correct 14 ms 2264 KB Output is correct
17 Correct 37 ms 4028 KB Output is correct
18 Correct 21 ms 2388 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 15 ms 1300 KB Output is correct
35 Correct 27 ms 3844 KB Output is correct
36 Correct 42 ms 3632 KB Output is correct
37 Correct 163 ms 3708 KB Output is correct
38 Correct 181 ms 3720 KB Output is correct
39 Correct 25 ms 3648 KB Output is correct
40 Correct 1 ms 292 KB Output is correct
41 Correct 27 ms 2108 KB Output is correct
42 Correct 38 ms 3700 KB Output is correct
43 Correct 6 ms 832 KB Output is correct
44 Correct 25 ms 2200 KB Output is correct
45 Correct 44 ms 3592 KB Output is correct
46 Correct 43 ms 3636 KB Output is correct
47 Correct 12 ms 2000 KB Output is correct
48 Correct 2 ms 368 KB Output is correct
49 Correct 147 ms 4252 KB Output is correct
50 Correct 47 ms 4244 KB Output is correct
51 Correct 81 ms 4152 KB Output is correct
52 Correct 45 ms 4160 KB Output is correct
53 Correct 35 ms 4288 KB Output is correct
54 Correct 169 ms 4244 KB Output is correct
55 Correct 32 ms 4200 KB Output is correct
56 Correct 64 ms 4156 KB Output is correct
57 Correct 46 ms 4188 KB Output is correct
58 Correct 750 ms 4232 KB Output is correct
59 Correct 814 ms 4404 KB Output is correct
60 Correct 754 ms 4196 KB Output is correct
61 Correct 786 ms 4240 KB Output is correct
62 Correct 714 ms 4276 KB Output is correct
63 Correct 815 ms 4488 KB Output is correct
64 Correct 733 ms 4232 KB Output is correct
65 Correct 0 ms 288 KB Output is correct
66 Correct 0 ms 312 KB Output is correct
67 Correct 766 ms 4200 KB Output is correct
68 Correct 780 ms 4152 KB Output is correct
69 Correct 673 ms 4224 KB Output is correct
70 Correct 749 ms 4164 KB Output is correct
71 Correct 730 ms 4276 KB Output is correct
72 Correct 693 ms 4268 KB Output is correct
73 Correct 730 ms 4272 KB Output is correct
74 Correct 777 ms 4244 KB Output is correct
75 Correct 711 ms 4268 KB Output is correct
76 Correct 785 ms 4216 KB Output is correct
77 Correct 124 ms 4436 KB Output is correct
78 Correct 50 ms 4124 KB Output is correct
79 Correct 93 ms 4276 KB Output is correct
80 Correct 87 ms 4208 KB Output is correct
81 Correct 88 ms 4236 KB Output is correct
82 Correct 76 ms 4256 KB Output is correct
83 Correct 51 ms 4196 KB Output is correct
84 Correct 479 ms 4284 KB Output is correct
85 Correct 816 ms 4304 KB Output is correct
86 Correct 1 ms 204 KB Output is correct
87 Correct 1 ms 308 KB Output is correct
88 Correct 839 ms 4396 KB Output is correct
89 Correct 158 ms 1356 KB Output is correct
90 Correct 0 ms 204 KB Output is correct