답안 #168995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168995 2019-12-17T11:43:40 Z cormac Chessboard (IZhO18_chessboard) C++14
100 / 100
404 ms 5132 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, int, int, int, int>;

ll INF = 1LL << 60;

int find(int p, int k) {
    return p / (2 * k) * k + min(k, p % (2 * k));
}

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

ll count2d(int x, int y, int w, int h, int 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);

    int N, K;
    ll A;
    cin >> N >> K;
    A = 1LL*N*N;
    
    vector<bk> blocks (K);
    F0R(i, K) {
        int x, y, w, h;
        cin >> x >> y >> w >> h;
        w-=x; h-=y;
        --x; --y; ++w; ++h;
        blocks[i] = make_tuple(1LL*w*h, y, x, h, w);
    }

    ll best = INF;

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

        ll c = count2d(0, 0, N, N, i);

        for (bk block : blocks) {
            int x, y, w, h; ll a;
            tie(a, x, y, w, h) = block;    
            ll overlap = count2d(x, y, w, h, i);
            c -= overlap;
            c += a - overlap;
        }

        best = min(best, c);
        best = min(best, A-c);
    }
    
    cout << best << endl;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3320 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 21 ms 2296 KB Output is correct
4 Correct 22 ms 2296 KB Output is correct
5 Correct 27 ms 2936 KB Output is correct
6 Correct 18 ms 1912 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 24 ms 1912 KB Output is correct
9 Correct 45 ms 4648 KB Output is correct
10 Correct 26 ms 2676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 416 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 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 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 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 416 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 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 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 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 352 KB Output is correct
16 Correct 14 ms 1400 KB Output is correct
17 Correct 35 ms 3708 KB Output is correct
18 Correct 45 ms 4216 KB Output is correct
19 Correct 88 ms 3832 KB Output is correct
20 Correct 98 ms 4244 KB Output is correct
21 Correct 33 ms 3576 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 24 ms 2040 KB Output is correct
24 Correct 41 ms 3896 KB Output is correct
25 Correct 6 ms 636 KB Output is correct
26 Correct 26 ms 2552 KB Output is correct
27 Correct 35 ms 3192 KB Output is correct
28 Correct 43 ms 4216 KB Output is correct
29 Correct 15 ms 1656 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3320 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 21 ms 2296 KB Output is correct
4 Correct 22 ms 2296 KB Output is correct
5 Correct 27 ms 2936 KB Output is correct
6 Correct 18 ms 1912 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 24 ms 1912 KB Output is correct
9 Correct 45 ms 4648 KB Output is correct
10 Correct 26 ms 2676 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 416 KB Output is correct
13 Correct 2 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 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 3 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 2 ms 352 KB Output is correct
26 Correct 14 ms 1400 KB Output is correct
27 Correct 35 ms 3708 KB Output is correct
28 Correct 45 ms 4216 KB Output is correct
29 Correct 88 ms 3832 KB Output is correct
30 Correct 98 ms 4244 KB Output is correct
31 Correct 33 ms 3576 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 24 ms 2040 KB Output is correct
34 Correct 41 ms 3896 KB Output is correct
35 Correct 6 ms 636 KB Output is correct
36 Correct 26 ms 2552 KB Output is correct
37 Correct 35 ms 3192 KB Output is correct
38 Correct 43 ms 4216 KB Output is correct
39 Correct 15 ms 1656 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 82 ms 4320 KB Output is correct
42 Correct 50 ms 4828 KB Output is correct
43 Correct 59 ms 4216 KB Output is correct
44 Correct 48 ms 4728 KB Output is correct
45 Correct 48 ms 5076 KB Output is correct
46 Correct 91 ms 4732 KB Output is correct
47 Correct 42 ms 4432 KB Output is correct
48 Correct 56 ms 4472 KB Output is correct
49 Correct 45 ms 4344 KB Output is correct
50 Correct 404 ms 4728 KB Output is correct
51 Correct 321 ms 4984 KB Output is correct
52 Correct 299 ms 4728 KB Output is correct
53 Correct 320 ms 4856 KB Output is correct
54 Correct 295 ms 4476 KB Output is correct
55 Correct 332 ms 5112 KB Output is correct
56 Correct 286 ms 4600 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 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 31 ms 3320 KB Output is correct
10 Correct 9 ms 1144 KB Output is correct
11 Correct 21 ms 2296 KB Output is correct
12 Correct 22 ms 2296 KB Output is correct
13 Correct 27 ms 2936 KB Output is correct
14 Correct 18 ms 1912 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 24 ms 1912 KB Output is correct
17 Correct 45 ms 4648 KB Output is correct
18 Correct 26 ms 2676 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 3 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 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 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 352 KB Output is correct
34 Correct 14 ms 1400 KB Output is correct
35 Correct 35 ms 3708 KB Output is correct
36 Correct 45 ms 4216 KB Output is correct
37 Correct 88 ms 3832 KB Output is correct
38 Correct 98 ms 4244 KB Output is correct
39 Correct 33 ms 3576 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 24 ms 2040 KB Output is correct
42 Correct 41 ms 3896 KB Output is correct
43 Correct 6 ms 636 KB Output is correct
44 Correct 26 ms 2552 KB Output is correct
45 Correct 35 ms 3192 KB Output is correct
46 Correct 43 ms 4216 KB Output is correct
47 Correct 15 ms 1656 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 82 ms 4320 KB Output is correct
50 Correct 50 ms 4828 KB Output is correct
51 Correct 59 ms 4216 KB Output is correct
52 Correct 48 ms 4728 KB Output is correct
53 Correct 48 ms 5076 KB Output is correct
54 Correct 91 ms 4732 KB Output is correct
55 Correct 42 ms 4432 KB Output is correct
56 Correct 56 ms 4472 KB Output is correct
57 Correct 45 ms 4344 KB Output is correct
58 Correct 404 ms 4728 KB Output is correct
59 Correct 321 ms 4984 KB Output is correct
60 Correct 299 ms 4728 KB Output is correct
61 Correct 320 ms 4856 KB Output is correct
62 Correct 295 ms 4476 KB Output is correct
63 Correct 332 ms 5112 KB Output is correct
64 Correct 286 ms 4600 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 312 ms 4820 KB Output is correct
68 Correct 309 ms 4856 KB Output is correct
69 Correct 269 ms 4344 KB Output is correct
70 Correct 296 ms 4728 KB Output is correct
71 Correct 293 ms 4600 KB Output is correct
72 Correct 286 ms 4544 KB Output is correct
73 Correct 281 ms 4344 KB Output is correct
74 Correct 308 ms 4728 KB Output is correct
75 Correct 289 ms 4584 KB Output is correct
76 Correct 313 ms 4856 KB Output is correct
77 Correct 78 ms 4984 KB Output is correct
78 Correct 50 ms 4572 KB Output is correct
79 Correct 64 ms 4344 KB Output is correct
80 Correct 63 ms 4600 KB Output is correct
81 Correct 59 ms 4216 KB Output is correct
82 Correct 59 ms 4856 KB Output is correct
83 Correct 49 ms 4516 KB Output is correct
84 Correct 198 ms 4856 KB Output is correct
85 Correct 330 ms 5112 KB Output is correct
86 Correct 2 ms 376 KB Output is correct
87 Correct 2 ms 376 KB Output is correct
88 Correct 332 ms 5132 KB Output is correct
89 Correct 63 ms 1272 KB Output is correct
90 Correct 3 ms 504 KB Output is correct