Submission #1108086

# Submission time Handle Problem Language Result Execution time Memory
1108086 2024-11-02T17:41:17 Z stdfloat Chessboard (IZhO18_chessboard) C++17
100 / 100
902 ms 4396 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define ff	first
#define ss	second
#define pii	pair<int, int>

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n, k;
	cin >> n >> k;

	pii p1[k], p2[k];
	for (int i = 0; i < k; i++) {
		cin >> p1[i].ff >> p1[i].ss >> p2[i].ff >> p2[i].ss;
		p1[i].ff--; p1[i].ss--; p2[i].ff--; p2[i].ss--;
	}

	ll ans = LLONG_MAX;
	for (int ii = 1; ii * ii <= n; ii++) {
		if (n % ii) continue;

		for (auto i : {ii, n / ii}) {
			if (i == n) continue;

			int x = n / i;
			ll cnt1 = ((ll)((x + 1) >> 1) * ((x + 1) >> 1) + (ll)(x >> 1) * (x >> 1)) * i * i;
			ll cnt2 = (ll)n * n - cnt1;
			for (int j = 0; j < k; j++) {
				pii x = p1[j], y = p2[j];

				vector<pair<pii, pii>> v;
				if (x.ss / i != y.ss / i) {
					if (x.ss % i) {
						v.push_back({x, {y.ff, x.ss + i - x.ss % i - 1}}); x.ss += i - x.ss % i;
					}
					if ((y.ss + 1) % i) {
						v.push_back({{x.ff, y.ss - y.ss % i}, y}); y.ss -= y.ss % i + 1;
					}
				}
				if (x.ff <= y.ff && x.ss <= y.ss) v.push_back({x, y});

				vector<pair<pii, pii>> u;
				for (auto [x, y] : v) {
					if (x.ff / i != y.ff / i) {
						if (x.ff % i) {
							u.push_back({x, {x.ff + i - x.ff % i - 1, y.ss}}); x.ff += i - x.ff % i;
						}
						if ((y.ff + 1) % i) {
							u.push_back({{y.ff - y.ff % i, x.ss}, y}); y.ff -= y.ff % i + 1;
						}
					}

					if (x.ff <= y.ff && x.ss <= y.ss) u.push_back({x, y});
				}

				for (auto [x, y] : u) {
					bool tr = (((x.ff / i) & 1) == ((x.ss / i) & 1));
					int r = max(1, (y.ff - x.ff + 1) / i), c = max(1, (y.ss - x.ss + 1) / i);

					cnt1 -= (ll)((r & 1) && (c & 1) ? (tr ? 1 : -1) : 0) * min(i, y.ff - x.ff + 1) * min(i, y.ss - x.ss + 1);
					cnt2 -= (ll)((r & 1) && (c & 1) ? (tr ? -1 : 1) : 0) * min(i, y.ff - x.ff + 1) * min(i, y.ss - x.ss + 1);
				}
			}

			ans = min({ans, cnt1, cnt2});
		}
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2816 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 12 ms 1828 KB Output is correct
4 Correct 13 ms 1872 KB Output is correct
5 Correct 19 ms 2384 KB Output is correct
6 Correct 11 ms 1628 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 12 ms 1816 KB Output is correct
9 Correct 30 ms 2280 KB Output is correct
10 Correct 15 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 572 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 572 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 1276 KB Output is correct
17 Correct 26 ms 2896 KB Output is correct
18 Correct 57 ms 3320 KB Output is correct
19 Correct 142 ms 3320 KB Output is correct
20 Correct 159 ms 3408 KB Output is correct
21 Correct 19 ms 2896 KB Output is correct
22 Correct 1 ms 508 KB Output is correct
23 Correct 27 ms 1616 KB Output is correct
24 Correct 31 ms 3292 KB Output is correct
25 Correct 5 ms 596 KB Output is correct
26 Correct 33 ms 2052 KB Output is correct
27 Correct 30 ms 2384 KB Output is correct
28 Correct 33 ms 3420 KB Output is correct
29 Correct 9 ms 1636 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2816 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 12 ms 1828 KB Output is correct
4 Correct 13 ms 1872 KB Output is correct
5 Correct 19 ms 2384 KB Output is correct
6 Correct 11 ms 1628 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 12 ms 1816 KB Output is correct
9 Correct 30 ms 2280 KB Output is correct
10 Correct 15 ms 2384 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 572 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 10 ms 1276 KB Output is correct
27 Correct 26 ms 2896 KB Output is correct
28 Correct 57 ms 3320 KB Output is correct
29 Correct 142 ms 3320 KB Output is correct
30 Correct 159 ms 3408 KB Output is correct
31 Correct 19 ms 2896 KB Output is correct
32 Correct 1 ms 508 KB Output is correct
33 Correct 27 ms 1616 KB Output is correct
34 Correct 31 ms 3292 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 33 ms 2052 KB Output is correct
37 Correct 30 ms 2384 KB Output is correct
38 Correct 33 ms 3420 KB Output is correct
39 Correct 9 ms 1636 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 123 ms 3664 KB Output is correct
42 Correct 35 ms 4168 KB Output is correct
43 Correct 82 ms 3668 KB Output is correct
44 Correct 45 ms 4080 KB Output is correct
45 Correct 27 ms 4168 KB Output is correct
46 Correct 165 ms 3920 KB Output is correct
47 Correct 40 ms 3676 KB Output is correct
48 Correct 53 ms 2508 KB Output is correct
49 Correct 37 ms 3664 KB Output is correct
50 Correct 657 ms 3868 KB Output is correct
51 Correct 707 ms 4268 KB Output is correct
52 Correct 664 ms 4000 KB Output is correct
53 Correct 730 ms 3888 KB Output is correct
54 Correct 679 ms 3920 KB Output is correct
55 Correct 720 ms 4388 KB Output is correct
56 Correct 633 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 32 ms 2816 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 12 ms 1828 KB Output is correct
12 Correct 13 ms 1872 KB Output is correct
13 Correct 19 ms 2384 KB Output is correct
14 Correct 11 ms 1628 KB Output is correct
15 Correct 3 ms 592 KB Output is correct
16 Correct 12 ms 1816 KB Output is correct
17 Correct 30 ms 2280 KB Output is correct
18 Correct 15 ms 2384 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 572 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 10 ms 1276 KB Output is correct
35 Correct 26 ms 2896 KB Output is correct
36 Correct 57 ms 3320 KB Output is correct
37 Correct 142 ms 3320 KB Output is correct
38 Correct 159 ms 3408 KB Output is correct
39 Correct 19 ms 2896 KB Output is correct
40 Correct 1 ms 508 KB Output is correct
41 Correct 27 ms 1616 KB Output is correct
42 Correct 31 ms 3292 KB Output is correct
43 Correct 5 ms 596 KB Output is correct
44 Correct 33 ms 2052 KB Output is correct
45 Correct 30 ms 2384 KB Output is correct
46 Correct 33 ms 3420 KB Output is correct
47 Correct 9 ms 1636 KB Output is correct
48 Correct 2 ms 336 KB Output is correct
49 Correct 123 ms 3664 KB Output is correct
50 Correct 35 ms 4168 KB Output is correct
51 Correct 82 ms 3668 KB Output is correct
52 Correct 45 ms 4080 KB Output is correct
53 Correct 27 ms 4168 KB Output is correct
54 Correct 165 ms 3920 KB Output is correct
55 Correct 40 ms 3676 KB Output is correct
56 Correct 53 ms 2508 KB Output is correct
57 Correct 37 ms 3664 KB Output is correct
58 Correct 657 ms 3868 KB Output is correct
59 Correct 707 ms 4268 KB Output is correct
60 Correct 664 ms 4000 KB Output is correct
61 Correct 730 ms 3888 KB Output is correct
62 Correct 679 ms 3920 KB Output is correct
63 Correct 720 ms 4388 KB Output is correct
64 Correct 633 ms 3408 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 868 ms 3116 KB Output is correct
68 Correct 875 ms 4124 KB Output is correct
69 Correct 743 ms 3668 KB Output is correct
70 Correct 783 ms 3920 KB Output is correct
71 Correct 782 ms 3920 KB Output is correct
72 Correct 764 ms 3664 KB Output is correct
73 Correct 790 ms 3808 KB Output is correct
74 Correct 876 ms 4088 KB Output is correct
75 Correct 794 ms 4168 KB Output is correct
76 Correct 849 ms 4056 KB Output is correct
77 Correct 125 ms 4176 KB Output is correct
78 Correct 39 ms 3920 KB Output is correct
79 Correct 87 ms 3676 KB Output is correct
80 Correct 91 ms 3920 KB Output is correct
81 Correct 99 ms 3656 KB Output is correct
82 Correct 70 ms 4096 KB Output is correct
83 Correct 55 ms 3664 KB Output is correct
84 Correct 521 ms 4168 KB Output is correct
85 Correct 902 ms 4168 KB Output is correct
86 Correct 2 ms 336 KB Output is correct
87 Correct 1 ms 336 KB Output is correct
88 Correct 887 ms 4396 KB Output is correct
89 Correct 190 ms 1104 KB Output is correct
90 Correct 1 ms 504 KB Output is correct