Submission #168974

# Submission time Handle Problem Language Result Execution time Memory
168974 2019-12-17T10:35:00 Z cormac Chessboard (IZhO18_chessboard) C++14
100 / 100
717 ms 4924 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, tA;
    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; tA += w * h;
        blocks[i] = make_tuple(w*h, y, x, h, w);
    }

    ll best = INF;

    ROF(i, 1, N) {
        if (N % i != 0) continue;

        ll cA = tA;
        
        ll c1 = count2d(0, 0, N, N, i);
        ll c2 = A - c1;

        for (bk block : blocks) {
            ll x, y, w, h, a;
            tie(a, x, y, w, h) = block;    
            ll overlap = count2d(x, y, w, h, i);
            cA -= a;
            c1 -= overlap;
            c1 += a - overlap;
            c2 += overlap;
            c2 -= a - overlap;
            if (c2 - cA >= best && c1 - cA >= best) break;
        }
        best = min(best, c1);
        best = min(best, c2);
    }
    
    cout << best << endl; 
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:59:16: warning: 'tA' may be used uninitialized in this function [-Wmaybe-uninitialized]
             cA -= a;
             ~~~^~~~
# 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3564 KB Output is correct
2 Correct 13 ms 1400 KB Output is correct
3 Correct 26 ms 2552 KB Output is correct
4 Correct 27 ms 2808 KB Output is correct
5 Correct 34 ms 3080 KB Output is correct
6 Correct 23 ms 2392 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 23 ms 2296 KB Output is correct
9 Correct 58 ms 4564 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 416 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 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 416 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 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 22 ms 1912 KB Output is correct
17 Correct 46 ms 4344 KB Output is correct
18 Correct 72 ms 4900 KB Output is correct
19 Correct 271 ms 4492 KB Output is correct
20 Correct 304 ms 4856 KB Output is correct
21 Correct 43 ms 4088 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 49 ms 2596 KB Output is correct
24 Correct 65 ms 4560 KB Output is correct
25 Correct 11 ms 760 KB Output is correct
26 Correct 42 ms 3236 KB Output is correct
27 Correct 66 ms 3704 KB Output is correct
28 Correct 71 ms 4804 KB Output is correct
29 Correct 19 ms 2188 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3564 KB Output is correct
2 Correct 13 ms 1400 KB Output is correct
3 Correct 26 ms 2552 KB Output is correct
4 Correct 27 ms 2808 KB Output is correct
5 Correct 34 ms 3080 KB Output is correct
6 Correct 23 ms 2392 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 23 ms 2296 KB Output is correct
9 Correct 58 ms 4564 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 416 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 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 22 ms 1912 KB Output is correct
27 Correct 46 ms 4344 KB Output is correct
28 Correct 72 ms 4900 KB Output is correct
29 Correct 271 ms 4492 KB Output is correct
30 Correct 304 ms 4856 KB Output is correct
31 Correct 43 ms 4088 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 49 ms 2596 KB Output is correct
34 Correct 65 ms 4560 KB Output is correct
35 Correct 11 ms 760 KB Output is correct
36 Correct 42 ms 3236 KB Output is correct
37 Correct 66 ms 3704 KB Output is correct
38 Correct 71 ms 4804 KB Output is correct
39 Correct 19 ms 2188 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 54 ms 4220 KB Output is correct
42 Correct 53 ms 4728 KB Output is correct
43 Correct 48 ms 4296 KB Output is correct
44 Correct 52 ms 4600 KB Output is correct
45 Correct 59 ms 4856 KB Output is correct
46 Correct 69 ms 4600 KB Output is correct
47 Correct 53 ms 4400 KB Output is correct
48 Correct 50 ms 4472 KB Output is correct
49 Correct 48 ms 4216 KB Output is correct
50 Correct 60 ms 4472 KB Output is correct
51 Correct 63 ms 4728 KB Output is correct
52 Correct 61 ms 4556 KB Output is correct
53 Correct 63 ms 4780 KB Output is correct
54 Correct 62 ms 4472 KB Output is correct
55 Correct 65 ms 4856 KB Output is correct
56 Correct 57 ms 4344 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 376 KB Output is correct
9 Correct 39 ms 3564 KB Output is correct
10 Correct 13 ms 1400 KB Output is correct
11 Correct 26 ms 2552 KB Output is correct
12 Correct 27 ms 2808 KB Output is correct
13 Correct 34 ms 3080 KB Output is correct
14 Correct 23 ms 2392 KB Output is correct
15 Correct 7 ms 888 KB Output is correct
16 Correct 23 ms 2296 KB Output is correct
17 Correct 58 ms 4564 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 416 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 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 22 ms 1912 KB Output is correct
35 Correct 46 ms 4344 KB Output is correct
36 Correct 72 ms 4900 KB Output is correct
37 Correct 271 ms 4492 KB Output is correct
38 Correct 304 ms 4856 KB Output is correct
39 Correct 43 ms 4088 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 49 ms 2596 KB Output is correct
42 Correct 65 ms 4560 KB Output is correct
43 Correct 11 ms 760 KB Output is correct
44 Correct 42 ms 3236 KB Output is correct
45 Correct 66 ms 3704 KB Output is correct
46 Correct 71 ms 4804 KB Output is correct
47 Correct 19 ms 2188 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 54 ms 4220 KB Output is correct
50 Correct 53 ms 4728 KB Output is correct
51 Correct 48 ms 4296 KB Output is correct
52 Correct 52 ms 4600 KB Output is correct
53 Correct 59 ms 4856 KB Output is correct
54 Correct 69 ms 4600 KB Output is correct
55 Correct 53 ms 4400 KB Output is correct
56 Correct 50 ms 4472 KB Output is correct
57 Correct 48 ms 4216 KB Output is correct
58 Correct 60 ms 4472 KB Output is correct
59 Correct 63 ms 4728 KB Output is correct
60 Correct 61 ms 4556 KB Output is correct
61 Correct 63 ms 4780 KB Output is correct
62 Correct 62 ms 4472 KB Output is correct
63 Correct 65 ms 4856 KB Output is correct
64 Correct 57 ms 4344 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 190 ms 4728 KB Output is correct
68 Correct 280 ms 4728 KB Output is correct
69 Correct 178 ms 4220 KB Output is correct
70 Correct 462 ms 4472 KB Output is correct
71 Correct 717 ms 4572 KB Output is correct
72 Correct 673 ms 4472 KB Output is correct
73 Correct 646 ms 4444 KB Output is correct
74 Correct 140 ms 4728 KB Output is correct
75 Correct 342 ms 4464 KB Output is correct
76 Correct 240 ms 4728 KB Output is correct
77 Correct 125 ms 4860 KB Output is correct
78 Correct 75 ms 4476 KB Output is correct
79 Correct 92 ms 4344 KB Output is correct
80 Correct 99 ms 4472 KB Output is correct
81 Correct 111 ms 4232 KB Output is correct
82 Correct 61 ms 4728 KB Output is correct
83 Correct 74 ms 4344 KB Output is correct
84 Correct 57 ms 4728 KB Output is correct
85 Correct 545 ms 4924 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 3 ms 376 KB Output is correct
88 Correct 210 ms 4856 KB Output is correct
89 Correct 34 ms 1528 KB Output is correct
90 Correct 3 ms 376 KB Output is correct