답안 #168983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168983 2019-12-17T11:09:29 Z cormac Chessboard (IZhO18_chessboard) C++14
100 / 100
443 ms 4416 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 find(ll p, ll k) {
    return p / (2 * k) * k + min(k, p % (2 * k));
}

ll count1d(ll x, ll w, ll k) {
    return find(x + w, k) - find(x, k);
}

ll count2d(ll x, ll y, ll w, ll h, ll k) {
    ll r = count1d(x, w, k); 
    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;
             ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2808 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 23 ms 1912 KB Output is correct
4 Correct 24 ms 2168 KB Output is correct
5 Correct 30 ms 2780 KB Output is correct
6 Correct 20 ms 2040 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 20 ms 1784 KB Output is correct
9 Correct 50 ms 4092 KB Output is correct
10 Correct 28 ms 2324 KB Output is correct
# 결과 실행 시간 메모리 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 380 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 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 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 380 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 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 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 16 ms 1400 KB Output is correct
17 Correct 38 ms 3704 KB Output is correct
18 Correct 56 ms 4264 KB Output is correct
19 Correct 173 ms 3832 KB Output is correct
20 Correct 192 ms 4216 KB Output is correct
21 Correct 36 ms 3448 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 34 ms 2040 KB Output is correct
24 Correct 50 ms 3832 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 32 ms 2552 KB Output is correct
27 Correct 46 ms 3084 KB Output is correct
28 Correct 54 ms 4088 KB Output is correct
29 Correct 16 ms 1656 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2808 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 23 ms 1912 KB Output is correct
4 Correct 24 ms 2168 KB Output is correct
5 Correct 30 ms 2780 KB Output is correct
6 Correct 20 ms 2040 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 20 ms 1784 KB Output is correct
9 Correct 50 ms 4092 KB Output is correct
10 Correct 28 ms 2324 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 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 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 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 16 ms 1400 KB Output is correct
27 Correct 38 ms 3704 KB Output is correct
28 Correct 56 ms 4264 KB Output is correct
29 Correct 173 ms 3832 KB Output is correct
30 Correct 192 ms 4216 KB Output is correct
31 Correct 36 ms 3448 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 34 ms 2040 KB Output is correct
34 Correct 50 ms 3832 KB Output is correct
35 Correct 8 ms 760 KB Output is correct
36 Correct 32 ms 2552 KB Output is correct
37 Correct 46 ms 3084 KB Output is correct
38 Correct 54 ms 4088 KB Output is correct
39 Correct 16 ms 1656 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 49 ms 3668 KB Output is correct
42 Correct 50 ms 4100 KB Output is correct
43 Correct 46 ms 3656 KB Output is correct
44 Correct 51 ms 3960 KB Output is correct
45 Correct 52 ms 4216 KB Output is correct
46 Correct 60 ms 3960 KB Output is correct
47 Correct 46 ms 3704 KB Output is correct
48 Correct 47 ms 3828 KB Output is correct
49 Correct 45 ms 3704 KB Output is correct
50 Correct 54 ms 3832 KB Output is correct
51 Correct 57 ms 4216 KB Output is correct
52 Correct 53 ms 3960 KB Output is correct
53 Correct 57 ms 4216 KB Output is correct
54 Correct 54 ms 3864 KB Output is correct
55 Correct 59 ms 4216 KB Output is correct
56 Correct 51 ms 3760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 34 ms 2808 KB Output is correct
10 Correct 10 ms 1016 KB Output is correct
11 Correct 23 ms 1912 KB Output is correct
12 Correct 24 ms 2168 KB Output is correct
13 Correct 30 ms 2780 KB Output is correct
14 Correct 20 ms 2040 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 20 ms 1784 KB Output is correct
17 Correct 50 ms 4092 KB Output is correct
18 Correct 28 ms 2324 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 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 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 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 16 ms 1400 KB Output is correct
35 Correct 38 ms 3704 KB Output is correct
36 Correct 56 ms 4264 KB Output is correct
37 Correct 173 ms 3832 KB Output is correct
38 Correct 192 ms 4216 KB Output is correct
39 Correct 36 ms 3448 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 34 ms 2040 KB Output is correct
42 Correct 50 ms 3832 KB Output is correct
43 Correct 8 ms 760 KB Output is correct
44 Correct 32 ms 2552 KB Output is correct
45 Correct 46 ms 3084 KB Output is correct
46 Correct 54 ms 4088 KB Output is correct
47 Correct 16 ms 1656 KB Output is correct
48 Correct 3 ms 504 KB Output is correct
49 Correct 49 ms 3668 KB Output is correct
50 Correct 50 ms 4100 KB Output is correct
51 Correct 46 ms 3656 KB Output is correct
52 Correct 51 ms 3960 KB Output is correct
53 Correct 52 ms 4216 KB Output is correct
54 Correct 60 ms 3960 KB Output is correct
55 Correct 46 ms 3704 KB Output is correct
56 Correct 47 ms 3828 KB Output is correct
57 Correct 45 ms 3704 KB Output is correct
58 Correct 54 ms 3832 KB Output is correct
59 Correct 57 ms 4216 KB Output is correct
60 Correct 53 ms 3960 KB Output is correct
61 Correct 57 ms 4216 KB Output is correct
62 Correct 54 ms 3864 KB Output is correct
63 Correct 59 ms 4216 KB Output is correct
64 Correct 51 ms 3760 KB Output is correct
65 Correct 2 ms 256 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 126 ms 4048 KB Output is correct
68 Correct 180 ms 3960 KB Output is correct
69 Correct 118 ms 3448 KB Output is correct
70 Correct 295 ms 3900 KB Output is correct
71 Correct 443 ms 3860 KB Output is correct
72 Correct 415 ms 3704 KB Output is correct
73 Correct 397 ms 3840 KB Output is correct
74 Correct 100 ms 4148 KB Output is correct
75 Correct 218 ms 3960 KB Output is correct
76 Correct 151 ms 4192 KB Output is correct
77 Correct 90 ms 4368 KB Output is correct
78 Correct 60 ms 3960 KB Output is correct
79 Correct 70 ms 3836 KB Output is correct
80 Correct 76 ms 4088 KB Output is correct
81 Correct 79 ms 3708 KB Output is correct
82 Correct 55 ms 4216 KB Output is correct
83 Correct 59 ms 3832 KB Output is correct
84 Correct 53 ms 4216 KB Output is correct
85 Correct 340 ms 4416 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 3 ms 256 KB Output is correct
88 Correct 142 ms 4412 KB Output is correct
89 Correct 24 ms 1016 KB Output is correct
90 Correct 3 ms 376 KB Output is correct