이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |