Submission #1108094

# Submission time Handle Problem Language Result Execution time Memory
1108094 2024-11-02T18:08:38 Z stdfloat Chessboard (IZhO18_chessboard) C++17
8 / 100
27 ms 1884 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;
			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.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) 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);
				}
			}

			ans = min(ans, cnt1);
		}
	}

	cout << min(ans, (ll)n * n - ans);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1360 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 12 ms 1232 KB Output is correct
4 Correct 13 ms 1172 KB Output is correct
5 Correct 16 ms 1272 KB Output is correct
6 Correct 11 ms 848 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 10 ms 848 KB Output is correct
9 Correct 27 ms 1884 KB Output is correct
10 Correct 15 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1360 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 12 ms 1232 KB Output is correct
4 Correct 13 ms 1172 KB Output is correct
5 Correct 16 ms 1272 KB Output is correct
6 Correct 11 ms 848 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 10 ms 848 KB Output is correct
9 Correct 27 ms 1884 KB Output is correct
10 Correct 15 ms 1104 KB Output is correct
11 Incorrect 1 ms 336 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 420 KB Output isn't correct
3 Halted 0 ms 0 KB -