이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 4107, L = 26, K = 66, MOD = 1000000007;
int main() {
// freopen("input.txt", "r", stdin);
// ios::sync_with_stdio(false); cin.tie(0);
int n, k;
scanf("%d%d", &n, &k);
vector < pair <int, int> > l(k), r(k);
long long sq = 0;
for (int i = 0; i < k; ++i) {
scanf("%d%d%d%d", &l[i].first, &l[i].second, &r[i].first, &r[i].second);
sq += 1LL * (r[i].first - l[i].first + 1) * (r[i].second - l[i].second + 1);
}
auto ways = [&](int l, int r, int d, int s) {
//return ((r - 1) / (2 * d) + max((r - 1) % (2 * d) - d, 0)) - (l > 1 ? (l - 2) / (2 * d) + max((l - 2) % (2 * d) - d, 0));
int cnt = 0;
for (int i = l; i <= r; ++i) {
cnt += (i - 1) / d % 2 == s;
}
return cnt;
};
auto calc = [&](int d, int s) {
long long ret = 0;
for (int i = 0; i < k; ++i) {
//lx[i] <= x <= rx[i] and ly[i] <= y <= ry[i] and (x-1)/d % 2 == 0 and (y-1)/d % 2 == 0
ret += 1LL * ways(l[i].first, r[i].first, d, s) * ways(l[i].second, r[i].second, d, s);
}
return (sq - ret) + 1LL * (1LL * (n / d) * (n / d) + 1 - s) / 2 * (1LL * d * d) - ret;
// min + 1LL * n * n - 1LL * (1LL * (n / d) * (n / d) + 1 - s) / 2 - (sq - ret) + ret;
};
long long ans = LLONG_MAX / 2;
for (int d = 1; d * d <= n; ++d) {
if (n % d == 0) {
ans = min(ans, calc(d, 0));
ans = min(ans, calc(d, 1));
if (d * d != n && d != 1) ans = min(ans, calc(n / d, 0));
if (d * d != n && d != 1) ans = min(ans, calc(n / d, 1));
}
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
chessboard.cpp: In function 'int main()':
chessboard.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d%d%d%d", &l[i].first, &l[i].second, &r[i].first, &r[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |