Submission #168590

# Submission time Handle Problem Language Result Execution time Memory
168590 2019-12-14T03:41:18 Z cormac Chessboard (IZhO18_chessboard) C++14
100 / 100
1274 ms 5248 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using bk = tuple<ll, ll, ll, ll, ll>;

ll INF = 1LL << 60;

ll count1d(ll x, ll w, ll k) {
    ll sx = k * ((x / k) + (x % k != 0));
    ll ex = (x + w) / k * k;
    if (ex < sx) return w;
    ll m = (ex - sx);
    return (sx - x) + (x + w - ex) * ((sx ==x) != (m/k%2==1)) + (m / k / 2) * k + k * ((m/k)%2 && (sx == x));
}

ll count2d(ll x, ll y, ll w, ll h, ll k) {
    ll r = count1d(x, w, k); 
    if ((x / k + y / k) % 2 == 1) r = w - r;
    ll c = count1d(y, h, k);
    return  r * c + (w-r) * (h-c);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll N, K, A;
    cin >> N >> K;
    A = N*N;
    
    vector<bk> blocks (K);
    F0R(i, K) {
        ll x, y, w, h;
        cin >> x >> y >> w >> h;
        w-=x; h-=y;
        --x; --y; ++w; ++h;
        blocks[i] = make_tuple(y, x, h, w, w*h);
    }

    ll best = INF;
    for (ll t = 1; t * t <= N; ++t) {
        if (N % t != 0) continue;
        for (ll i : {t, N / t}) {
            if (i == N) continue;
            ll c1 = count2d(0, 0, N, N, i);
            ll c2 = A - c1;
            for (bk block : blocks) {
                ll x, y, w, h, a;
                tie(x, y, w, h, a) = block;    
                ll overlap = count2d(x, y, w, h, i);
                c1 -= overlap;
                c1 += a - overlap;
                c2 -= a - overlap;
                c2 += overlap;
            }
            best = min(best, c1);
            best = min(best, c2);
        }
    }
    cout << best << endl; 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3624 KB Output is correct
2 Correct 11 ms 1400 KB Output is correct
3 Correct 25 ms 2172 KB Output is correct
4 Correct 28 ms 3064 KB Output is correct
5 Correct 34 ms 3192 KB Output is correct
6 Correct 22 ms 2168 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 22 ms 2520 KB Output is correct
9 Correct 56 ms 4600 KB Output is correct
10 Correct 32 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 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 2 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 388 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 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 2 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 388 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 23 ms 1912 KB Output is correct
17 Correct 44 ms 4344 KB Output is correct
18 Correct 72 ms 5028 KB Output is correct
19 Correct 271 ms 4612 KB Output is correct
20 Correct 303 ms 5112 KB Output is correct
21 Correct 43 ms 4472 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 49 ms 2780 KB Output is correct
24 Correct 66 ms 4600 KB Output is correct
25 Correct 11 ms 888 KB Output is correct
26 Correct 45 ms 3320 KB Output is correct
27 Correct 65 ms 3832 KB Output is correct
28 Correct 72 ms 4828 KB Output is correct
29 Correct 19 ms 2168 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3624 KB Output is correct
2 Correct 11 ms 1400 KB Output is correct
3 Correct 25 ms 2172 KB Output is correct
4 Correct 28 ms 3064 KB Output is correct
5 Correct 34 ms 3192 KB Output is correct
6 Correct 22 ms 2168 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 22 ms 2520 KB Output is correct
9 Correct 56 ms 4600 KB Output is correct
10 Correct 32 ms 3064 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 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 2 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 388 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 23 ms 1912 KB Output is correct
27 Correct 44 ms 4344 KB Output is correct
28 Correct 72 ms 5028 KB Output is correct
29 Correct 271 ms 4612 KB Output is correct
30 Correct 303 ms 5112 KB Output is correct
31 Correct 43 ms 4472 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 49 ms 2780 KB Output is correct
34 Correct 66 ms 4600 KB Output is correct
35 Correct 11 ms 888 KB Output is correct
36 Correct 45 ms 3320 KB Output is correct
37 Correct 65 ms 3832 KB Output is correct
38 Correct 72 ms 4828 KB Output is correct
39 Correct 19 ms 2168 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 219 ms 4344 KB Output is correct
42 Correct 73 ms 4728 KB Output is correct
43 Correct 131 ms 4472 KB Output is correct
44 Correct 74 ms 4728 KB Output is correct
45 Correct 58 ms 4984 KB Output is correct
46 Correct 243 ms 4884 KB Output is correct
47 Correct 51 ms 4548 KB Output is correct
48 Correct 100 ms 4600 KB Output is correct
49 Correct 67 ms 4600 KB Output is correct
50 Correct 1084 ms 4728 KB Output is correct
51 Correct 1155 ms 4984 KB Output is correct
52 Correct 1076 ms 4688 KB Output is correct
53 Correct 1148 ms 4956 KB Output is correct
54 Correct 1059 ms 4604 KB Output is correct
55 Correct 1192 ms 5248 KB Output is correct
56 Correct 1027 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 404 KB Output is correct
9 Correct 39 ms 3624 KB Output is correct
10 Correct 11 ms 1400 KB Output is correct
11 Correct 25 ms 2172 KB Output is correct
12 Correct 28 ms 3064 KB Output is correct
13 Correct 34 ms 3192 KB Output is correct
14 Correct 22 ms 2168 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 22 ms 2520 KB Output is correct
17 Correct 56 ms 4600 KB Output is correct
18 Correct 32 ms 3064 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 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 2 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 388 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 23 ms 1912 KB Output is correct
35 Correct 44 ms 4344 KB Output is correct
36 Correct 72 ms 5028 KB Output is correct
37 Correct 271 ms 4612 KB Output is correct
38 Correct 303 ms 5112 KB Output is correct
39 Correct 43 ms 4472 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 49 ms 2780 KB Output is correct
42 Correct 66 ms 4600 KB Output is correct
43 Correct 11 ms 888 KB Output is correct
44 Correct 45 ms 3320 KB Output is correct
45 Correct 65 ms 3832 KB Output is correct
46 Correct 72 ms 4828 KB Output is correct
47 Correct 19 ms 2168 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 219 ms 4344 KB Output is correct
50 Correct 73 ms 4728 KB Output is correct
51 Correct 131 ms 4472 KB Output is correct
52 Correct 74 ms 4728 KB Output is correct
53 Correct 58 ms 4984 KB Output is correct
54 Correct 243 ms 4884 KB Output is correct
55 Correct 51 ms 4548 KB Output is correct
56 Correct 100 ms 4600 KB Output is correct
57 Correct 67 ms 4600 KB Output is correct
58 Correct 1084 ms 4728 KB Output is correct
59 Correct 1155 ms 4984 KB Output is correct
60 Correct 1076 ms 4688 KB Output is correct
61 Correct 1148 ms 4956 KB Output is correct
62 Correct 1059 ms 4604 KB Output is correct
63 Correct 1192 ms 5248 KB Output is correct
64 Correct 1027 ms 4548 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 1200 ms 4856 KB Output is correct
68 Correct 1194 ms 4856 KB Output is correct
69 Correct 1031 ms 4220 KB Output is correct
70 Correct 1123 ms 4664 KB Output is correct
71 Correct 1147 ms 4728 KB Output is correct
72 Correct 1098 ms 4540 KB Output is correct
73 Correct 1095 ms 4604 KB Output is correct
74 Correct 1190 ms 4796 KB Output is correct
75 Correct 1116 ms 4600 KB Output is correct
76 Correct 1203 ms 4828 KB Output is correct
77 Correct 196 ms 4984 KB Output is correct
78 Correct 72 ms 4756 KB Output is correct
79 Correct 135 ms 4472 KB Output is correct
80 Correct 141 ms 4600 KB Output is correct
81 Correct 133 ms 4356 KB Output is correct
82 Correct 113 ms 4896 KB Output is correct
83 Correct 88 ms 4472 KB Output is correct
84 Correct 718 ms 4944 KB Output is correct
85 Correct 1274 ms 5060 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 380 KB Output is correct
88 Correct 1271 ms 5112 KB Output is correct
89 Correct 246 ms 1528 KB Output is correct
90 Correct 2 ms 376 KB Output is correct