# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
202243 | 2020-02-14T13:39:47 Z | ZwariowanyMarcin | Chessboard (IZhO18_chessboard) | C++14 | 203 ms | 3448 KB |
#include <bits/stdc++.h> #define LL long long #define pb push_back #define make_pair #define ss(x) (int) x.size() #define fi first #define se second #define cat(x) cerr << #x << " = " << x << endl using namespace std; const int nax = 1e5 + 11; const LL INF = 1e18; int n, k; LL best = INF; struct pt { int x, y, xx, yy; }; pt t[nax]; LL rec(int bok, int x, int y) { int X = x / bok; int Y = y / bok; LL black = 0; if (X % 2 == 0 || Y % 2 == 0) { black += (LL) X * Y / 2 * bok * bok; } else { black += (LL) ((X * Y) / 2 + 1) * bok * bok; } if (X % 2 == Y % 2) { black += (LL) (x - X * bok) * (y - Y * bok); } if (Y % 2 == 0) { black += (LL) (X + 1) / 2 * (y - Y * bok) * bok; } else { black += (LL) X / 2 * (y - Y * bok) * bok; } if (X % 2 == 0) { black += (LL) (Y + 1) / 2 * (x - X * bok) * bok; } else { black += (LL) Y / 2 * (x - X * bok) * bok; } return black; } void solve(int bok) { LL sum = 0; LL pole = 0; for (int i = 0; i < k; ++i) { sum += rec(bok, t[i].xx, t[i].yy) - rec(bok, t[i].x - 1, t[i].yy) - rec(bok, t[i].xx, t[i].y - 1) + rec(bok, t[i].x - 1, t[i].y - 1); pole += (LL) (t[i].xx - t[i].x + 1) * (t[i].yy - t[i].y + 1); } LL black = rec(bok, n, n); LL white = (LL) n * n - black; /*if (bok == 2) { cat(rec(2, t[0].x - 1, t[0].yy)); cat(black); cat(white); cat(sum); cat(pole); } */ best = min(best, (black - sum) + (pole - sum)); best = min(best, (white - (pole - sum)) + sum); } int main() { scanf ("%d%d", &n, &k); for (int i = 0; i < k; ++i) scanf ("%d %d %d %d", &t[i].x, &t[i].y, &t[i].xx, &t[i].yy); for (int i = 1; i < n; ++i) if (n % i == 0) solve(i); printf ("%lld", best); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 6 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 2936 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 6 ms | 376 KB | Output is correct |
14 | Correct | 6 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 6 ms | 376 KB | Output is correct |
14 | Correct | 6 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 21 ms | 1272 KB | Output is correct |
17 | Correct | 46 ms | 2992 KB | Output is correct |
18 | Correct | 62 ms | 3448 KB | Output is correct |
19 | Correct | 181 ms | 3192 KB | Output is correct |
20 | Correct | 203 ms | 3448 KB | Output is correct |
21 | Correct | 41 ms | 2936 KB | Output is correct |
22 | Correct | 5 ms | 376 KB | Output is correct |
23 | Correct | 40 ms | 1656 KB | Output is correct |
24 | Correct | 56 ms | 3196 KB | Output is correct |
25 | Correct | 12 ms | 632 KB | Output is correct |
26 | Correct | 37 ms | 2144 KB | Output is correct |
27 | Correct | 58 ms | 2680 KB | Output is correct |
28 | Correct | 62 ms | 3320 KB | Output is correct |
29 | Correct | 22 ms | 1400 KB | Output is correct |
30 | Correct | 6 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 2936 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 6 ms | 256 KB | Output is correct |
9 | Incorrect | 41 ms | 2936 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |