이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, k, a[N], b[N], c[N], d[N];
long long ans = 1e18;
long long white(int n, int m, int x){
int a = n / x, b = m / x;
long long ret = ((a * 1ll * b + 1) / 2) * 1ll * x * x;
if(a % 2 == 0){
ret += ((b + 1) / 2) * 1ll * (n - a *1ll* x) * x;
} else {
ret += (b / 2) * 1ll * (n - a *1ll* x) * x;
}
if(b % 2 == 0){
ret += ((a + 1) / 2) * 1ll * (m - b *1ll* x) * x;
} else {
ret += (a / 2) * 1ll * (m - b *1ll* x) * x;
}
if(a % 2 == 0 && b % 2 == 0)
ret += (n - a *1ll* x) * 1ll * (m - b *1ll* x);
return ret;
}
long long get(int x){
long long ret, cc = n / x;
ret = ((cc * cc) / 2) * 1ll * x * x;
for(int i = k; i <= k; i ++){
long long wh = white(c[i], d[i], x) - white(a[i] - 1, d[i], x) - white(c[i], b[i] - 1, x) + white(a[i] - 1, b[i] - 1, x);
ret -= (c[i] - a[i] + 1) * 1ll * (d[i] - b[i] + 1) - wh;
}
for(int i = 1; i <= k; i ++){
long long wh = white(c[i], d[i], x) - white(a[i] - 1, d[i], x) - white(c[i], b[i] - 1, x) + white(a[i] - 1, b[i] - 1, x);
ret += wh;
}
return min(ret, n * 1ll * n - ret);
}
int main(){
scanf("%d %d", &n, &k);
for(int i = 1; i <= k; i ++){
scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
}
for(int i = 1; i * i <= n; i ++){
if(n % i == 0){
ans = min(ans, get(i));
if(i != 1)
ans = min(ans, get(n / i));
}
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
chessboard.cpp: In function 'int main()':
chessboard.cpp:43:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |