이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
using namespace std;
typedef long long ll;
const ll N = 1e3 + 5;
int n, k, pref[N][N];
main() {
cin >> n >> k;
for(int kk = 1; kk <= k; kk++) {
int x, y, xx, yy;
cin >> x >> y >> xx >> yy;
for(int i = x; i <= xx; i++) {
for(int j = y; j <= yy; j++) {
pref[i][j] = 1;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
}
int ans = n * n;
for(int z = 1; z < n; z++) {
if(n % z == 0) {
short type = 1;
int res1 = 0, res2 = 0;
for(int i = z; i <= n; i += z) {
for(int j = z; j <= n; j += z) {
if(type) {
res1 += pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z];
res2 += z * z - (pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z]);
} else {
res1 += z * z - (pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z]);
res2 += pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z];
}
type = 1 - type;
}
}
ans = min(ans, min(res1, res2));
}
}
cout << ans;
}
/*
5
2 8 5 1 10
5
2 3 5 3
2 5 3 3
1 4 4
2 3 4 2
1 1 2
*/
컴파일 시 표준 에러 (stderr) 메시지
chessboard.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
17 | main() {
| ^~~~
# | 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... |