# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
93131 | 2019-01-06T14:55:26 Z | SamAnd | Chessboard (IZhO18_chessboard) | C++17 | 2000 ms | 3488 KB |
#include <iostream> #include <cstdio> using namespace std; #define m_p make_pair const int N = 100005; struct ban { long long x, y; ban(){} ban(long long x, long long y) { this->x = x; this->y = y; } }; long long n; int m; pair<ban, ban> a[N]; bool vv; bool sevv(long long x, long long y, long long t) { x = x / t; y = y / t; if ((x + y) % 2 == 0) { if (vv) return true; else return false; } else { if (vv) return false; else return true; } } long long sev(const pair<ban, ban>& a, long long t) { long long x1 = a.first.x; long long y1 = a.first.y; long long x2 = a.second.x; long long y2 = a.second.y; if (x1 == 0 && y1 == 1 && x2 == 0 && y2 == 1 && t == 3) cout << ""; long long xm1 = (x1 / t + 1) * t; if (x1 % t == 0) xm1 = x1; long long xm2 = (x2 / t) * t - 1; if (x2 % t == t - 1) xm2 = x2; long long ym1 = (y1 / t + 1) * t; if (y1 % t == 0) ym1 = y1; long long ym2 = (y2 / t) * t - 1; if (y2 % t == t - 1) ym2 = y2; long long ans = 0; long long xx = 0; if (xm1 - xm2 == t + 1) { if (sevv(x1, y1, t)) xx = (x2 - x1 + 1); goto kovx; } // x1; xm1 - 1 if (sevv(x1, y1, t)) xx += (xm1 - x1); // xm1; xm2 if (sevv(xm1, y1, t)) xx += ((((xm2 - xm1 + 1) / t) / 2) * t); else xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t); // xm2 + 1; x2 if (sevv(xm2 + 1, y1, t)) xx += (x2 - xm2); kovx: if (ym1 - ym2 == t + 1) { ans = (xx * (y2 - y1 + 1)); goto kovy; } // y1; ym1 - 1 if (sevv(x1, y1, t)) ans += ((ym1 - y1) * xx); // ym1; ym2 ans += ((((ym2 - ym1 + 1) / t) / 2) * xx * t); ans += ((((ym2 - ym1 + 1) / t) - (((ym2 - ym1 + 1) / t) / 2)) * ((x2 - x1 + 1) - xx) * t); // ym2 + 1; y2 if (sevv(x1, y1, t) == sevv(x1, y2, t)) ans += ((y2 - ym2) * xx); else ans += ((y2 - ym2) * ((x2 - x1 + 1) - xx)); kovy: return ans; } long long spi(const pair<ban, ban>& a, long long t) { long long x1 = a.first.x; long long y1 = a.first.y; long long x2 = a.second.x; long long y2 = a.second.y; return (x2 - x1 + 1) * (y2 - y1 + 1) - sev(a, t); } long long ans; void stg(long long t) { vv = true; long long yans = 0; long long g = 0; for (int i = 0; i < m; ++i) { yans += (spi(a[i], t)); g += (sev(a[i], t)); } yans += (sev(m_p(ban(0, 0), ban(n - 1, n - 1)), t) - g); ans = min(ans, yans); vv = false; yans = 0; g = 0; for (int i = 0; i < m; ++i) { yans += (spi(a[i], t)); g += (sev(a[i], t)); } yans += (sev(m_p(ban(0, 0), ban(n - 1, n - 1)), t) - g); ans = min(ans, yans); } int main() { //freopen("input2.txt", "r", stdin); //cin >> n >> m; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d%d%d%d", &a[i].first.x, &a[i].first.y, &a[i].second.x, &a[i].second.y); --a[i].first.x; --a[i].first.y; --a[i].second.x; --a[i].second.y; } ans = n * n; for (long long i = 1; i * i <= n; ++i) { if (n % i == 0) { if (i != n) stg(i); if (n / i != n) stg(n / i); } } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 2196 KB | Output is correct |
2 | Correct | 14 ms | 888 KB | Output is correct |
3 | Correct | 33 ms | 1532 KB | Output is correct |
4 | Correct | 36 ms | 1784 KB | Output is correct |
5 | Correct | 44 ms | 2040 KB | Output is correct |
6 | Correct | 29 ms | 1376 KB | Output is correct |
7 | Correct | 7 ms | 504 KB | Output is correct |
8 | Correct | 29 ms | 1528 KB | Output is correct |
9 | Correct | 73 ms | 3128 KB | Output is correct |
10 | Correct | 40 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 4 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 4 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
16 | Correct | 36 ms | 1272 KB | Output is correct |
17 | Correct | 61 ms | 2936 KB | Output is correct |
18 | Correct | 119 ms | 3488 KB | Output is correct |
19 | Correct | 609 ms | 3124 KB | Output is correct |
20 | Correct | 676 ms | 3448 KB | Output is correct |
21 | Correct | 60 ms | 2936 KB | Output is correct |
22 | Correct | 3 ms | 376 KB | Output is correct |
23 | Correct | 96 ms | 1784 KB | Output is correct |
24 | Correct | 109 ms | 3192 KB | Output is correct |
25 | Correct | 20 ms | 632 KB | Output is correct |
26 | Correct | 71 ms | 2168 KB | Output is correct |
27 | Correct | 125 ms | 2524 KB | Output is correct |
28 | Correct | 128 ms | 3320 KB | Output is correct |
29 | Correct | 26 ms | 1400 KB | Output is correct |
30 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 2196 KB | Output is correct |
2 | Correct | 14 ms | 888 KB | Output is correct |
3 | Correct | 33 ms | 1532 KB | Output is correct |
4 | Correct | 36 ms | 1784 KB | Output is correct |
5 | Correct | 44 ms | 2040 KB | Output is correct |
6 | Correct | 29 ms | 1376 KB | Output is correct |
7 | Correct | 7 ms | 504 KB | Output is correct |
8 | Correct | 29 ms | 1528 KB | Output is correct |
9 | Correct | 73 ms | 3128 KB | Output is correct |
10 | Correct | 40 ms | 1912 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 4 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 3 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 4 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 376 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 36 ms | 1272 KB | Output is correct |
27 | Correct | 61 ms | 2936 KB | Output is correct |
28 | Correct | 119 ms | 3488 KB | Output is correct |
29 | Correct | 609 ms | 3124 KB | Output is correct |
30 | Correct | 676 ms | 3448 KB | Output is correct |
31 | Correct | 60 ms | 2936 KB | Output is correct |
32 | Correct | 3 ms | 376 KB | Output is correct |
33 | Correct | 96 ms | 1784 KB | Output is correct |
34 | Correct | 109 ms | 3192 KB | Output is correct |
35 | Correct | 20 ms | 632 KB | Output is correct |
36 | Correct | 71 ms | 2168 KB | Output is correct |
37 | Correct | 125 ms | 2524 KB | Output is correct |
38 | Correct | 128 ms | 3320 KB | Output is correct |
39 | Correct | 26 ms | 1400 KB | Output is correct |
40 | Correct | 5 ms | 376 KB | Output is correct |
41 | Correct | 473 ms | 3064 KB | Output is correct |
42 | Correct | 113 ms | 3196 KB | Output is correct |
43 | Correct | 258 ms | 2936 KB | Output is correct |
44 | Correct | 126 ms | 3192 KB | Output is correct |
45 | Correct | 81 ms | 3448 KB | Output is correct |
46 | Correct | 526 ms | 3268 KB | Output is correct |
47 | Correct | 70 ms | 2936 KB | Output is correct |
48 | Correct | 182 ms | 3192 KB | Output is correct |
49 | Correct | 107 ms | 2936 KB | Output is correct |
50 | Execution timed out | 2048 ms | 3192 KB | Time limit exceeded |
51 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 51 ms | 2196 KB | Output is correct |
10 | Correct | 14 ms | 888 KB | Output is correct |
11 | Correct | 33 ms | 1532 KB | Output is correct |
12 | Correct | 36 ms | 1784 KB | Output is correct |
13 | Correct | 44 ms | 2040 KB | Output is correct |
14 | Correct | 29 ms | 1376 KB | Output is correct |
15 | Correct | 7 ms | 504 KB | Output is correct |
16 | Correct | 29 ms | 1528 KB | Output is correct |
17 | Correct | 73 ms | 3128 KB | Output is correct |
18 | Correct | 40 ms | 1912 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 4 ms | 376 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 376 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 3 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 2 ms | 376 KB | Output is correct |
29 | Correct | 3 ms | 376 KB | Output is correct |
30 | Correct | 2 ms | 376 KB | Output is correct |
31 | Correct | 4 ms | 376 KB | Output is correct |
32 | Correct | 3 ms | 376 KB | Output is correct |
33 | Correct | 3 ms | 376 KB | Output is correct |
34 | Correct | 36 ms | 1272 KB | Output is correct |
35 | Correct | 61 ms | 2936 KB | Output is correct |
36 | Correct | 119 ms | 3488 KB | Output is correct |
37 | Correct | 609 ms | 3124 KB | Output is correct |
38 | Correct | 676 ms | 3448 KB | Output is correct |
39 | Correct | 60 ms | 2936 KB | Output is correct |
40 | Correct | 3 ms | 376 KB | Output is correct |
41 | Correct | 96 ms | 1784 KB | Output is correct |
42 | Correct | 109 ms | 3192 KB | Output is correct |
43 | Correct | 20 ms | 632 KB | Output is correct |
44 | Correct | 71 ms | 2168 KB | Output is correct |
45 | Correct | 125 ms | 2524 KB | Output is correct |
46 | Correct | 128 ms | 3320 KB | Output is correct |
47 | Correct | 26 ms | 1400 KB | Output is correct |
48 | Correct | 5 ms | 376 KB | Output is correct |
49 | Correct | 473 ms | 3064 KB | Output is correct |
50 | Correct | 113 ms | 3196 KB | Output is correct |
51 | Correct | 258 ms | 2936 KB | Output is correct |
52 | Correct | 126 ms | 3192 KB | Output is correct |
53 | Correct | 81 ms | 3448 KB | Output is correct |
54 | Correct | 526 ms | 3268 KB | Output is correct |
55 | Correct | 70 ms | 2936 KB | Output is correct |
56 | Correct | 182 ms | 3192 KB | Output is correct |
57 | Correct | 107 ms | 2936 KB | Output is correct |
58 | Execution timed out | 2048 ms | 3192 KB | Time limit exceeded |
59 | Halted | 0 ms | 0 KB | - |