답안 #715009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715009 2023-03-25T17:48:36 Z Stickfish Chessboard (IZhO18_chessboard) C++17
70 / 100
511 ms 3412 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

bool get_color(pair<ll, ll> p, ll d) {
    return (p.first / d + p.second / d) & 1;
}

ll llersect(pair<pair<ll, ll>, pair<ll, ll>> r1, pair<pair<ll, ll>, pair<ll, ll>> r2) {
    ll w = min(r1.second.first, r2.second.first) - max(r1.first.first, r2.first.first);
    ll h = min(r1.second.second, r2.second.second) - max(r1.first.second, r2.first.second);
    if (w < 0 || h < 0)
        return 0;
    return w * h;
}

signed main() {
    ll n, k;
    cin >> n >> k;
    vector<pair<pair<ll, ll>, pair<ll, ll>>> rect(k);
    for (ll i = 0; i < k; ++i) {
        cin >> rect[i].first.first >> rect[i].first.second >> rect[i].second.first >> rect[i].second.second;
        --rect[i].first.first, --rect[i].first.second, --rect[i].second.first, --rect[i].second.second;
    }
    vector<ll> divs;
    for (ll p = 1; p < n; ++p) {
        if (n % p == 0)
            divs.push_back(p);
    }
    ll szd = divs.size();
    vector<ll> ans(szd);
    for (ll di = 0; di < szd; ++di) {
        ll d = divs[di];
        if (n / d == 0)
            ans[di] = n * n / 2;
        else
            ans[di] = d * d * ((n / d) * (n / d) / 2);
    }
    for (auto [ld, ru] : rect) {
        for (ll di = 0; di < szd; ++di) {
            ll d = divs[di];
            ll r = ld.first + (ru.first - ld.first) % (2 * d);
            ll u = ld.second + (ru.second - ld.second) % (2 * d);
            pair<pair<ll, ll>, pair<ll, ll>> rct = {ld, {r + 1, u + 1}};

            ll bi = ld.first / (2 * d) * (2 * d);
            ll bj = ld.second / (2 * d) * (2 * d);
            ans[di] += llersect(rct, {{bi, bj}, {bi + d, bj + d}});
            ans[di] -= llersect(rct, {{bi + d, bj}, {bi + 2 * d, bj + d}});
            ans[di] -= llersect(rct, {{bi, bj + d}, {bi + d, bj + 2 * d}});
            ans[di] += llersect(rct, {{bi + d, bj + d}, {bi + 2 * d, bj + 2 * d}});
        }
    }
    ll mnans = n * n;
    for (auto x : ans) {
        mnans = min({mnans, x, n * n - x});
    }
    cout << mnans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2260 KB Output is correct
2 Correct 17 ms 724 KB Output is correct
3 Correct 47 ms 1516 KB Output is correct
4 Correct 42 ms 1620 KB Output is correct
5 Correct 56 ms 2004 KB Output is correct
6 Correct 36 ms 1364 KB Output is correct
7 Correct 8 ms 468 KB Output is correct
8 Correct 38 ms 1364 KB Output is correct
9 Correct 92 ms 3120 KB Output is correct
10 Correct 56 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 27 ms 1168 KB Output is correct
17 Correct 73 ms 2928 KB Output is correct
18 Correct 96 ms 3400 KB Output is correct
19 Correct 169 ms 3064 KB Output is correct
20 Correct 185 ms 3284 KB Output is correct
21 Correct 66 ms 2832 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 43 ms 1620 KB Output is correct
24 Correct 85 ms 3104 KB Output is correct
25 Correct 9 ms 468 KB Output is correct
26 Correct 49 ms 2004 KB Output is correct
27 Correct 70 ms 2412 KB Output is correct
28 Correct 101 ms 3284 KB Output is correct
29 Correct 31 ms 1328 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2260 KB Output is correct
2 Correct 17 ms 724 KB Output is correct
3 Correct 47 ms 1516 KB Output is correct
4 Correct 42 ms 1620 KB Output is correct
5 Correct 56 ms 2004 KB Output is correct
6 Correct 36 ms 1364 KB Output is correct
7 Correct 8 ms 468 KB Output is correct
8 Correct 38 ms 1364 KB Output is correct
9 Correct 92 ms 3120 KB Output is correct
10 Correct 56 ms 1876 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 27 ms 1168 KB Output is correct
27 Correct 73 ms 2928 KB Output is correct
28 Correct 96 ms 3400 KB Output is correct
29 Correct 169 ms 3064 KB Output is correct
30 Correct 185 ms 3284 KB Output is correct
31 Correct 66 ms 2832 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 43 ms 1620 KB Output is correct
34 Correct 85 ms 3104 KB Output is correct
35 Correct 9 ms 468 KB Output is correct
36 Correct 49 ms 2004 KB Output is correct
37 Correct 70 ms 2412 KB Output is correct
38 Correct 101 ms 3284 KB Output is correct
39 Correct 31 ms 1328 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 149 ms 2900 KB Output is correct
42 Correct 108 ms 3228 KB Output is correct
43 Correct 119 ms 2900 KB Output is correct
44 Correct 100 ms 3136 KB Output is correct
45 Correct 118 ms 3360 KB Output is correct
46 Correct 177 ms 3188 KB Output is correct
47 Correct 96 ms 2972 KB Output is correct
48 Correct 121 ms 3028 KB Output is correct
49 Correct 96 ms 2900 KB Output is correct
50 Correct 454 ms 3028 KB Output is correct
51 Correct 478 ms 3324 KB Output is correct
52 Correct 466 ms 3116 KB Output is correct
53 Correct 511 ms 3284 KB Output is correct
54 Correct 463 ms 3080 KB Output is correct
55 Correct 508 ms 3412 KB Output is correct
56 Correct 434 ms 2992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 65 ms 2260 KB Output is correct
10 Correct 17 ms 724 KB Output is correct
11 Correct 47 ms 1516 KB Output is correct
12 Correct 42 ms 1620 KB Output is correct
13 Correct 56 ms 2004 KB Output is correct
14 Correct 36 ms 1364 KB Output is correct
15 Correct 8 ms 468 KB Output is correct
16 Correct 38 ms 1364 KB Output is correct
17 Correct 92 ms 3120 KB Output is correct
18 Correct 56 ms 1876 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 27 ms 1168 KB Output is correct
35 Correct 73 ms 2928 KB Output is correct
36 Correct 96 ms 3400 KB Output is correct
37 Correct 169 ms 3064 KB Output is correct
38 Correct 185 ms 3284 KB Output is correct
39 Correct 66 ms 2832 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 43 ms 1620 KB Output is correct
42 Correct 85 ms 3104 KB Output is correct
43 Correct 9 ms 468 KB Output is correct
44 Correct 49 ms 2004 KB Output is correct
45 Correct 70 ms 2412 KB Output is correct
46 Correct 101 ms 3284 KB Output is correct
47 Correct 31 ms 1328 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 149 ms 2900 KB Output is correct
50 Correct 108 ms 3228 KB Output is correct
51 Correct 119 ms 2900 KB Output is correct
52 Correct 100 ms 3136 KB Output is correct
53 Correct 118 ms 3360 KB Output is correct
54 Correct 177 ms 3188 KB Output is correct
55 Correct 96 ms 2972 KB Output is correct
56 Correct 121 ms 3028 KB Output is correct
57 Correct 96 ms 2900 KB Output is correct
58 Correct 454 ms 3028 KB Output is correct
59 Correct 478 ms 3324 KB Output is correct
60 Correct 466 ms 3116 KB Output is correct
61 Correct 511 ms 3284 KB Output is correct
62 Correct 463 ms 3080 KB Output is correct
63 Correct 508 ms 3412 KB Output is correct
64 Correct 434 ms 2992 KB Output is correct
65 Correct 2 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Incorrect 492 ms 3224 KB Output isn't correct
68 Halted 0 ms 0 KB -