# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
167772 | abil | Chessboard (IZhO18_chessboard) | C++14 | 38 ms | 3832 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int ans = 1e9;
int n, k, x[2][N], y[2][N];
void calc(int div){
int bl = n / div, cnt = 0, x1, y1;
if(bl & 1){
cnt += div * div * ((bl + 1) / 2) * ((bl + 1) / 2);
cnt += div * div * (bl / 2) * (bl / 2);
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + bl - 1) / bl;
y1 = (y1 + bl - 1) / bl;
if((x1 + y1) % 2 == 1){
cnt++;
}
else{
cnt--;
}
}
ans = min(ans, cnt);
cnt = 0;
cnt += div * div * ((bl + 1) / 2) * ((bl + 1) / 2);
cnt += div * div * (bl / 2) * (bl / 2);
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + bl - 1) / bl;
y1 = (y1 + bl - 1) / bl;
if((x1 + y1) % 2 == 0){
cnt++;
}
else{
cnt--;
}
}
ans = min(ans, cnt);
}
else{
cnt += div * div * (bl / 2) * bl;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + bl - 1) / bl;
y1 = (y1 + bl - 1) / bl;
if((x1 + y1) % 2 == 1){
cnt++;
}
else{
cnt--;
}
}
ans = min(ans, cnt);
cnt = 0;
cnt += div * div * (bl / 2) * bl;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + bl - 1) / bl;
y1 = (y1 + bl - 1) / bl;
if((x1 + y1) % 2 == 0){
cnt++;
}
else{
cnt--;
}
}
ans = min(ans, cnt);
}
}
main()
{
cin >> n >> k;
for(int i = 1;i <= k; i++){
scanf("%lld%lld%lld%lld", &x[0][i], &y[0][i], &x[1][i], &y[1][i]);
}
for(int i = 1;i * i <= n; i++){
if(n % i == 0){
calc(i);
calc(n / i);
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |