# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99770 | choikiwon | Chessboard (IZhO18_chessboard) | C++17 | 171 ms | 3832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 100010;
int N, K;
struct Rect {
int r1, c1, r2, c2;
};
Rect rect[MN];
int main() {
scanf("%d %d", &N, &K);
for(int i = 0; i < K; i++) {
scanf("%d %d %d %d", &rect[i].r1, &rect[i].c1, &rect[i].r2, &rect[i].c2);
rect[i].r1--;
rect[i].c1--;
rect[i].r2--;
rect[i].c2--;
}
ll mn = 1e18;
for(int i = 1; i < N; i++) {
if(N % i == 0) {
for(int j = 0; j < 2; j++) {
int n = N / i;
ll tmp = j? (1LL * n * n + 1) / 2 : 1LL * n * n / 2;
tmp *= i * i;
for(int k = 0; k < K; k++) {
int rr = min(rect[k].r2 + 1, (rect[k].r1 + i) / i * i);
int cc = min(rect[k].c2 + 1, (rect[k].c1 + i) / i * i);
int br = (rect[k].r2 - rr + 1) / (2 * i);
int bc = (rect[k].c2 - cc + 1) / (2 * i);
if((rect[k].r2 - rr + 1) % (2 * i) > i) br += (rect[k].r2 - rr + 1) % (2 * i) - i;
if((rect[k].c2 - cc + 1) % (2 * i) > i) bc += (rect[k].c2 - cc + 1) % (2 * i) - i;
br += rr - rect[k].r1;
bc += cc - rect[k].c1;
int wr = rect[k].r2 - rect[k].r1 + 1 - br;
int wc = rect[k].c2 - rect[k].c1 + 1 - bc;
if(j ^ ((rect[k].r1 / i + rect[k].c1 / i) & 1)) tmp -= 1LL * (br - wr) * (bc - wc);
else tmp += 1LL * (br - wr) * (bc - wc);
}
mn = min(mn, tmp);
}
}
}
printf("%lld", mn);
}
Compilation message (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... |