Submission #898334

#TimeUsernameProblemLanguageResultExecution timeMemory
898334marcidChessboard (IZhO18_chessboard)C++17
0 / 100
19 ms4724 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct rect { int x1, y1, x2, y2; }; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vector<rect> a; int n, k; cin >> n >> k; for (int i = 0; i < k; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; a.push_back({x1, y1, x2, y2}); } int res = n * n; int wh_cnt[n + 1], bl_cnt[n + 1]; for (int d = 2; d < n; d++) { if (n % d) continue; wh_cnt[0] = 0; bl_cnt[0] = 0; for (int i = 1; i <= n; i++) { int id = (i + d - 1) / d; wh_cnt[i] = wh_cnt[i - 1]; bl_cnt[i] = bl_cnt[i - 1]; if (id % 2) { wh_cnt[i]++; } else { bl_cnt[i]++; } } int cur = (n / d) * (n / d) / 2 * d * d; for (auto [x1, y1, x2, y2] : a) { cur += (wh_cnt[x2] - wh_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]); cur -= (wh_cnt[x2] - wh_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]); } res = min({res, cur, n * n - cur}); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...