Submission #50842

#TimeUsernameProblemLanguageResultExecution timeMemory
50842NicksechkoChessboard (IZhO18_chessboard)C++14
100 / 100
715 ms2300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MX = 100 * 1000 + 7; #define y1 ak_a_kak_podnyat int x1[MX], y1[MX], x2[MX], y2[MX]; pair<int, int> slv(int l, int r, int s) { if (l / s == r / s) { int b = l / s; if (b & 1) { return {0, r - l + 1}; } else { return {r - l + 1, 0}; } } else { pair<int, int> a(0, 0); int nl = l - l % s + s, nr = r - r % s - 1; if ((l / s) % 2 == 0) { a.first += nl - l; } else { a.second += nl - l; } if ((r / s) % 2 == 0) { a.first += r - nr; } else { a.second += r - nr; } int bl = (nr - nl + 1) / s; if (bl & 1) { if ((nl / s) % 2 == 0) { a.first += s; } else { a.second += s; } bl--; } a.first += (bl / 2) * s; a.second += (bl / 2) * s; return a; } } ll solve(int n, int m, int s) { ll g0 = 0, g1 = 0; for (int i = 0; i < m; i++) { auto p1 = slv(x1[i], x2[i], s); auto p2 = slv(y1[i], y2[i], s); g0 += 1LL * p1.first * p2.first; g0 += 1LL * p1.second * p2.second; g1 += 1LL * p1.second * p2.first; g1 += 1LL * p1.first * p2.second; } n /= s; ll b0 = (1LL * n * n + 1) / 2 * s * s; ll b1 = (1LL * n * n) / 2 * s * s; return min(g0 + b1 - g1, g1 + b0 - g0); } int main() { #ifdef AZINO777 freopen("in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]); x1[i]--; y1[i]--; x2[i]--; y2[i]--; } ll ans = 2e18; for (int i = 1; i < n; i++) { if (n % i == 0) { ans = min(ans, solve(n, m, i)); } } printf("%lld\n", ans); }

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...