제출 #1092398

#제출 시각아이디문제언어결과실행 시간메모리
1092398juicyChessboard (IZhO18_chessboard)C++17
100 / 100
136 ms4444 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

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

  auto calc = [&](int i, int l) {
    return i / (2 * l) * l + min(l, i % (2 * l));
  };

  int n, k; cin >> n >> k;
  vector<array<int, 4>> rect(k);
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < 4; ++j) {
      cin >> rect[i][j];
    }
  }
  long long res = (long long) n * n;
  for (int l = 1; l < n; ++l) {
    if (n % l == 0) {
      long long x = 2LL * calc(n, l) * (n - calc(n, l));
      for (auto [r1, c1, r2, c2] : rect) {
        int r = calc(r2, l) - calc(r1 - 1, l), c = calc(c2, l) - calc(c1 - 1, l);
        int cr = r2 - r1 + 1, cc = c2 - c1 + 1;
        x += 2LL * r * c + 2LL * (cr - r) * (cc - c) - (long long) cr * cc;
      }
      res = min({res, x, (long long) n * n - x});
    }
  }
  cout << res;
  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...