# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40565 | 2018-02-05T01:42:35 Z | Just_Solve_The_Problem | Chessboard (IZhO18_chessboard) | C++11 | 1409 ms | 3820 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define whatis(x) cout << #x << " is -> " << x << endl; const ll linf = (ll)1e18 + 7; const ll N = (ll)1e5 + 7; ll x1[N], YY[N], x2[N], y2[N]; ll n; ll k; ll ans = linf; inline ll gety(ll y,ll len){ if(y <= 0) return 0; ll res = (y / len) / 2 * len; if((y / len) & 1) res += y % len + 1; return res; } inline ll getx(ll x,ll len){ if(x <= 0) return 0; ll res = (x / len) / 2 * len; if((x / len) & 1) res += x % len + 1; return res; } void calc(ll len) { ll odd = 0, even = 0; for(ll i = 1,xx,yy; i <= k; i++){ ll o1 = gety(y2[i], len) - gety(YY[i] - 1, len); ll e1 = (y2[i] - YY[i] + 1) - o1; ll o2 = getx(x2[i], len) - getx(x1[i] - 1, len); ll e2 = (x2[i] - x1[i] + 1) - o2; xx = x1[i] / len; yy = YY[i] / len; if(xx & 1) swap(o1,e1); if(yy & 1) swap(o2,e2); ll od = 0, ev = 0; if((xx + yy) & 1){ od = e1 * e2 + o1 * o2; } else{ od = o1 * e2 + e1 * o2; } ev = 1ll * (x2[i] - x1[i] + 1) * (y2[i] - YY[i] + 1) - od; odd += od; even += ev; } ll cnt = 1ll * (n / len) * (n / len); ll res = min(cnt / 2 * len * len + even - odd, (cnt + 1) / 2 * len * len + odd - even); if(res < ans){ ans = res; } } main () { scanf("%lld %d", &n, &k); for (ll i = 1; i <= k; i++) { ll a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); a--; b--; c--; d--; x1[i] = a; YY[i] = b; x2[i] = c; y2[i] = d; } for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { calc(i); if (i != 1 && n / i != i) calc(n / i); } } printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 248 KB | Output is correct |
2 | Correct | 1 ms | 352 KB | Output is correct |
3 | Correct | 2 ms | 388 KB | Output is correct |
4 | Correct | 2 ms | 652 KB | Output is correct |
5 | Correct | 1 ms | 652 KB | Output is correct |
6 | Correct | 2 ms | 652 KB | Output is correct |
7 | Correct | 2 ms | 652 KB | Output is correct |
8 | Correct | 2 ms | 652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 2524 KB | Output is correct |
2 | Correct | 12 ms | 2524 KB | Output is correct |
3 | Correct | 27 ms | 2524 KB | Output is correct |
4 | Correct | 28 ms | 2524 KB | Output is correct |
5 | Correct | 39 ms | 2524 KB | Output is correct |
6 | Correct | 39 ms | 2524 KB | Output is correct |
7 | Correct | 6 ms | 2524 KB | Output is correct |
8 | Correct | 24 ms | 2524 KB | Output is correct |
9 | Correct | 57 ms | 3404 KB | Output is correct |
10 | Correct | 34 ms | 3404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3404 KB | Output is correct |
2 | Correct | 2 ms | 3404 KB | Output is correct |
3 | Correct | 2 ms | 3404 KB | Output is correct |
4 | Correct | 3 ms | 3404 KB | Output is correct |
5 | Correct | 2 ms | 3404 KB | Output is correct |
6 | Correct | 2 ms | 3404 KB | Output is correct |
7 | Correct | 2 ms | 3404 KB | Output is correct |
8 | Correct | 2 ms | 3404 KB | Output is correct |
9 | Correct | 2 ms | 3404 KB | Output is correct |
10 | Correct | 2 ms | 3404 KB | Output is correct |
11 | Correct | 2 ms | 3404 KB | Output is correct |
12 | Correct | 2 ms | 3404 KB | Output is correct |
13 | Correct | 3 ms | 3404 KB | Output is correct |
14 | Correct | 3 ms | 3404 KB | Output is correct |
15 | Correct | 2 ms | 3404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3404 KB | Output is correct |
2 | Correct | 2 ms | 3404 KB | Output is correct |
3 | Correct | 2 ms | 3404 KB | Output is correct |
4 | Correct | 3 ms | 3404 KB | Output is correct |
5 | Correct | 2 ms | 3404 KB | Output is correct |
6 | Correct | 2 ms | 3404 KB | Output is correct |
7 | Correct | 2 ms | 3404 KB | Output is correct |
8 | Correct | 2 ms | 3404 KB | Output is correct |
9 | Correct | 2 ms | 3404 KB | Output is correct |
10 | Correct | 2 ms | 3404 KB | Output is correct |
11 | Correct | 2 ms | 3404 KB | Output is correct |
12 | Correct | 2 ms | 3404 KB | Output is correct |
13 | Correct | 3 ms | 3404 KB | Output is correct |
14 | Correct | 3 ms | 3404 KB | Output is correct |
15 | Correct | 2 ms | 3404 KB | Output is correct |
16 | Correct | 21 ms | 3404 KB | Output is correct |
17 | Correct | 43 ms | 3404 KB | Output is correct |
18 | Correct | 74 ms | 3724 KB | Output is correct |
19 | Correct | 283 ms | 3724 KB | Output is correct |
20 | Correct | 352 ms | 3820 KB | Output is correct |
21 | Correct | 46 ms | 3820 KB | Output is correct |
22 | Correct | 3 ms | 3820 KB | Output is correct |
23 | Correct | 49 ms | 3820 KB | Output is correct |
24 | Correct | 68 ms | 3820 KB | Output is correct |
25 | Correct | 12 ms | 3820 KB | Output is correct |
26 | Correct | 45 ms | 3820 KB | Output is correct |
27 | Correct | 68 ms | 3820 KB | Output is correct |
28 | Correct | 79 ms | 3820 KB | Output is correct |
29 | Correct | 25 ms | 3820 KB | Output is correct |
30 | Correct | 4 ms | 3820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 2524 KB | Output is correct |
2 | Correct | 12 ms | 2524 KB | Output is correct |
3 | Correct | 27 ms | 2524 KB | Output is correct |
4 | Correct | 28 ms | 2524 KB | Output is correct |
5 | Correct | 39 ms | 2524 KB | Output is correct |
6 | Correct | 39 ms | 2524 KB | Output is correct |
7 | Correct | 6 ms | 2524 KB | Output is correct |
8 | Correct | 24 ms | 2524 KB | Output is correct |
9 | Correct | 57 ms | 3404 KB | Output is correct |
10 | Correct | 34 ms | 3404 KB | Output is correct |
11 | Correct | 2 ms | 3404 KB | Output is correct |
12 | Correct | 2 ms | 3404 KB | Output is correct |
13 | Correct | 2 ms | 3404 KB | Output is correct |
14 | Correct | 3 ms | 3404 KB | Output is correct |
15 | Correct | 2 ms | 3404 KB | Output is correct |
16 | Correct | 2 ms | 3404 KB | Output is correct |
17 | Correct | 2 ms | 3404 KB | Output is correct |
18 | Correct | 2 ms | 3404 KB | Output is correct |
19 | Correct | 2 ms | 3404 KB | Output is correct |
20 | Correct | 2 ms | 3404 KB | Output is correct |
21 | Correct | 2 ms | 3404 KB | Output is correct |
22 | Correct | 2 ms | 3404 KB | Output is correct |
23 | Correct | 3 ms | 3404 KB | Output is correct |
24 | Correct | 3 ms | 3404 KB | Output is correct |
25 | Correct | 2 ms | 3404 KB | Output is correct |
26 | Correct | 21 ms | 3404 KB | Output is correct |
27 | Correct | 43 ms | 3404 KB | Output is correct |
28 | Correct | 74 ms | 3724 KB | Output is correct |
29 | Correct | 283 ms | 3724 KB | Output is correct |
30 | Correct | 352 ms | 3820 KB | Output is correct |
31 | Correct | 46 ms | 3820 KB | Output is correct |
32 | Correct | 3 ms | 3820 KB | Output is correct |
33 | Correct | 49 ms | 3820 KB | Output is correct |
34 | Correct | 68 ms | 3820 KB | Output is correct |
35 | Correct | 12 ms | 3820 KB | Output is correct |
36 | Correct | 45 ms | 3820 KB | Output is correct |
37 | Correct | 68 ms | 3820 KB | Output is correct |
38 | Correct | 79 ms | 3820 KB | Output is correct |
39 | Correct | 25 ms | 3820 KB | Output is correct |
40 | Correct | 4 ms | 3820 KB | Output is correct |
41 | Correct | 246 ms | 3820 KB | Output is correct |
42 | Correct | 75 ms | 3820 KB | Output is correct |
43 | Correct | 151 ms | 3820 KB | Output is correct |
44 | Correct | 77 ms | 3820 KB | Output is correct |
45 | Correct | 59 ms | 3820 KB | Output is correct |
46 | Correct | 278 ms | 3820 KB | Output is correct |
47 | Correct | 54 ms | 3820 KB | Output is correct |
48 | Correct | 105 ms | 3820 KB | Output is correct |
49 | Correct | 79 ms | 3820 KB | Output is correct |
50 | Correct | 1252 ms | 3820 KB | Output is correct |
51 | Correct | 1276 ms | 3820 KB | Output is correct |
52 | Correct | 1184 ms | 3820 KB | Output is correct |
53 | Correct | 1302 ms | 3820 KB | Output is correct |
54 | Correct | 1191 ms | 3820 KB | Output is correct |
55 | Correct | 1332 ms | 3820 KB | Output is correct |
56 | Correct | 1175 ms | 3820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 248 KB | Output is correct |
2 | Correct | 1 ms | 352 KB | Output is correct |
3 | Correct | 2 ms | 388 KB | Output is correct |
4 | Correct | 2 ms | 652 KB | Output is correct |
5 | Correct | 1 ms | 652 KB | Output is correct |
6 | Correct | 2 ms | 652 KB | Output is correct |
7 | Correct | 2 ms | 652 KB | Output is correct |
8 | Correct | 2 ms | 652 KB | Output is correct |
9 | Correct | 39 ms | 2524 KB | Output is correct |
10 | Correct | 12 ms | 2524 KB | Output is correct |
11 | Correct | 27 ms | 2524 KB | Output is correct |
12 | Correct | 28 ms | 2524 KB | Output is correct |
13 | Correct | 39 ms | 2524 KB | Output is correct |
14 | Correct | 39 ms | 2524 KB | Output is correct |
15 | Correct | 6 ms | 2524 KB | Output is correct |
16 | Correct | 24 ms | 2524 KB | Output is correct |
17 | Correct | 57 ms | 3404 KB | Output is correct |
18 | Correct | 34 ms | 3404 KB | Output is correct |
19 | Correct | 2 ms | 3404 KB | Output is correct |
20 | Correct | 2 ms | 3404 KB | Output is correct |
21 | Correct | 2 ms | 3404 KB | Output is correct |
22 | Correct | 3 ms | 3404 KB | Output is correct |
23 | Correct | 2 ms | 3404 KB | Output is correct |
24 | Correct | 2 ms | 3404 KB | Output is correct |
25 | Correct | 2 ms | 3404 KB | Output is correct |
26 | Correct | 2 ms | 3404 KB | Output is correct |
27 | Correct | 2 ms | 3404 KB | Output is correct |
28 | Correct | 2 ms | 3404 KB | Output is correct |
29 | Correct | 2 ms | 3404 KB | Output is correct |
30 | Correct | 2 ms | 3404 KB | Output is correct |
31 | Correct | 3 ms | 3404 KB | Output is correct |
32 | Correct | 3 ms | 3404 KB | Output is correct |
33 | Correct | 2 ms | 3404 KB | Output is correct |
34 | Correct | 21 ms | 3404 KB | Output is correct |
35 | Correct | 43 ms | 3404 KB | Output is correct |
36 | Correct | 74 ms | 3724 KB | Output is correct |
37 | Correct | 283 ms | 3724 KB | Output is correct |
38 | Correct | 352 ms | 3820 KB | Output is correct |
39 | Correct | 46 ms | 3820 KB | Output is correct |
40 | Correct | 3 ms | 3820 KB | Output is correct |
41 | Correct | 49 ms | 3820 KB | Output is correct |
42 | Correct | 68 ms | 3820 KB | Output is correct |
43 | Correct | 12 ms | 3820 KB | Output is correct |
44 | Correct | 45 ms | 3820 KB | Output is correct |
45 | Correct | 68 ms | 3820 KB | Output is correct |
46 | Correct | 79 ms | 3820 KB | Output is correct |
47 | Correct | 25 ms | 3820 KB | Output is correct |
48 | Correct | 4 ms | 3820 KB | Output is correct |
49 | Correct | 246 ms | 3820 KB | Output is correct |
50 | Correct | 75 ms | 3820 KB | Output is correct |
51 | Correct | 151 ms | 3820 KB | Output is correct |
52 | Correct | 77 ms | 3820 KB | Output is correct |
53 | Correct | 59 ms | 3820 KB | Output is correct |
54 | Correct | 278 ms | 3820 KB | Output is correct |
55 | Correct | 54 ms | 3820 KB | Output is correct |
56 | Correct | 105 ms | 3820 KB | Output is correct |
57 | Correct | 79 ms | 3820 KB | Output is correct |
58 | Correct | 1252 ms | 3820 KB | Output is correct |
59 | Correct | 1276 ms | 3820 KB | Output is correct |
60 | Correct | 1184 ms | 3820 KB | Output is correct |
61 | Correct | 1302 ms | 3820 KB | Output is correct |
62 | Correct | 1191 ms | 3820 KB | Output is correct |
63 | Correct | 1332 ms | 3820 KB | Output is correct |
64 | Correct | 1175 ms | 3820 KB | Output is correct |
65 | Correct | 2 ms | 3820 KB | Output is correct |
66 | Correct | 1 ms | 3820 KB | Output is correct |
67 | Correct | 1315 ms | 3820 KB | Output is correct |
68 | Correct | 1272 ms | 3820 KB | Output is correct |
69 | Correct | 1132 ms | 3820 KB | Output is correct |
70 | Correct | 1202 ms | 3820 KB | Output is correct |
71 | Correct | 1194 ms | 3820 KB | Output is correct |
72 | Correct | 1166 ms | 3820 KB | Output is correct |
73 | Correct | 1202 ms | 3820 KB | Output is correct |
74 | Correct | 1295 ms | 3820 KB | Output is correct |
75 | Correct | 1231 ms | 3820 KB | Output is correct |
76 | Correct | 1338 ms | 3820 KB | Output is correct |
77 | Correct | 263 ms | 3820 KB | Output is correct |
78 | Correct | 95 ms | 3820 KB | Output is correct |
79 | Correct | 165 ms | 3820 KB | Output is correct |
80 | Correct | 162 ms | 3820 KB | Output is correct |
81 | Correct | 138 ms | 3820 KB | Output is correct |
82 | Correct | 119 ms | 3820 KB | Output is correct |
83 | Correct | 105 ms | 3820 KB | Output is correct |
84 | Correct | 775 ms | 3820 KB | Output is correct |
85 | Correct | 1409 ms | 3820 KB | Output is correct |
86 | Correct | 3 ms | 3820 KB | Output is correct |
87 | Correct | 2 ms | 3820 KB | Output is correct |
88 | Correct | 1373 ms | 3820 KB | Output is correct |
89 | Correct | 276 ms | 3820 KB | Output is correct |
90 | Correct | 1 ms | 3820 KB | Output is correct |