Submission #715012

# Submission time Handle Problem Language Result Execution time Memory
715012 2023-03-25T18:01:36 Z Stickfish Chessboard (IZhO18_chessboard) C++17
100 / 100
936 ms 5828 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 intersect(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);
    //cout << w << ' ' << h << endl;
    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);
            for (ll i = 0; i < 4; ++i) for (ll j = 0; j < 4; ++j) {
                ll val = intersect(rct, {{bi + d * i, bj + d * j}, {bi + d * i + d, bj + d * j + d}});
                if ((i + j) % 2)
                    ans[di] -= val;
                else
                    ans[di] += val;
            }
            //ans[di] += intersect(rct, {{bi, bj}, {bi + d, bj + d}});
            //ans[di] -= intersect(rct, {{bi + d, bj}, {bi + 2 * d, bj + d}});
            //ans[di] -= intersect(rct, {{bi, bj + d}, {bi + d, bj + 2 * d}});
            //ans[di] += intersect(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';
}
# Verdict Execution time Memory 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 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2264 KB Output is correct
2 Correct 21 ms 724 KB Output is correct
3 Correct 46 ms 1492 KB Output is correct
4 Correct 44 ms 1720 KB Output is correct
5 Correct 59 ms 2004 KB Output is correct
6 Correct 37 ms 1364 KB Output is correct
7 Correct 8 ms 536 KB Output is correct
8 Correct 39 ms 1364 KB Output is correct
9 Correct 96 ms 3176 KB Output is correct
10 Correct 52 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 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 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 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 1 ms 212 KB Output is correct
16 Correct 30 ms 1168 KB Output is correct
17 Correct 70 ms 2900 KB Output is correct
18 Correct 97 ms 3396 KB Output is correct
19 Correct 219 ms 3048 KB Output is correct
20 Correct 256 ms 3388 KB Output is correct
21 Correct 68 ms 2824 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 52 ms 1620 KB Output is correct
24 Correct 86 ms 3028 KB Output is correct
25 Correct 10 ms 468 KB Output is correct
26 Correct 54 ms 2004 KB Output is correct
27 Correct 75 ms 2388 KB Output is correct
28 Correct 98 ms 3284 KB Output is correct
29 Correct 29 ms 1324 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2264 KB Output is correct
2 Correct 21 ms 724 KB Output is correct
3 Correct 46 ms 1492 KB Output is correct
4 Correct 44 ms 1720 KB Output is correct
5 Correct 59 ms 2004 KB Output is correct
6 Correct 37 ms 1364 KB Output is correct
7 Correct 8 ms 536 KB Output is correct
8 Correct 39 ms 1364 KB Output is correct
9 Correct 96 ms 3176 KB Output is correct
10 Correct 52 ms 1876 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 2 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 1 ms 212 KB Output is correct
26 Correct 30 ms 1168 KB Output is correct
27 Correct 70 ms 2900 KB Output is correct
28 Correct 97 ms 3396 KB Output is correct
29 Correct 219 ms 3048 KB Output is correct
30 Correct 256 ms 3388 KB Output is correct
31 Correct 68 ms 2824 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 52 ms 1620 KB Output is correct
34 Correct 86 ms 3028 KB Output is correct
35 Correct 10 ms 468 KB Output is correct
36 Correct 54 ms 2004 KB Output is correct
37 Correct 75 ms 2388 KB Output is correct
38 Correct 98 ms 3284 KB Output is correct
39 Correct 29 ms 1324 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 212 ms 2900 KB Output is correct
42 Correct 112 ms 3240 KB Output is correct
43 Correct 150 ms 2900 KB Output is correct
44 Correct 114 ms 3156 KB Output is correct
45 Correct 104 ms 3356 KB Output is correct
46 Correct 229 ms 3156 KB Output is correct
47 Correct 90 ms 2968 KB Output is correct
48 Correct 126 ms 3008 KB Output is correct
49 Correct 103 ms 2900 KB Output is correct
50 Correct 814 ms 3132 KB Output is correct
51 Correct 879 ms 3408 KB Output is correct
52 Correct 824 ms 3236 KB Output is correct
53 Correct 865 ms 3408 KB Output is correct
54 Correct 812 ms 3200 KB Output is correct
55 Correct 896 ms 3420 KB Output is correct
56 Correct 785 ms 2992 KB Output is correct
# Verdict Execution time Memory 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 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 66 ms 2264 KB Output is correct
10 Correct 21 ms 724 KB Output is correct
11 Correct 46 ms 1492 KB Output is correct
12 Correct 44 ms 1720 KB Output is correct
13 Correct 59 ms 2004 KB Output is correct
14 Correct 37 ms 1364 KB Output is correct
15 Correct 8 ms 536 KB Output is correct
16 Correct 39 ms 1364 KB Output is correct
17 Correct 96 ms 3176 KB Output is correct
18 Correct 52 ms 1876 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 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 1 ms 212 KB Output is correct
34 Correct 30 ms 1168 KB Output is correct
35 Correct 70 ms 2900 KB Output is correct
36 Correct 97 ms 3396 KB Output is correct
37 Correct 219 ms 3048 KB Output is correct
38 Correct 256 ms 3388 KB Output is correct
39 Correct 68 ms 2824 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 52 ms 1620 KB Output is correct
42 Correct 86 ms 3028 KB Output is correct
43 Correct 10 ms 468 KB Output is correct
44 Correct 54 ms 2004 KB Output is correct
45 Correct 75 ms 2388 KB Output is correct
46 Correct 98 ms 3284 KB Output is correct
47 Correct 29 ms 1324 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 212 ms 2900 KB Output is correct
50 Correct 112 ms 3240 KB Output is correct
51 Correct 150 ms 2900 KB Output is correct
52 Correct 114 ms 3156 KB Output is correct
53 Correct 104 ms 3356 KB Output is correct
54 Correct 229 ms 3156 KB Output is correct
55 Correct 90 ms 2968 KB Output is correct
56 Correct 126 ms 3008 KB Output is correct
57 Correct 103 ms 2900 KB Output is correct
58 Correct 814 ms 3132 KB Output is correct
59 Correct 879 ms 3408 KB Output is correct
60 Correct 824 ms 3236 KB Output is correct
61 Correct 865 ms 3408 KB Output is correct
62 Correct 812 ms 3200 KB Output is correct
63 Correct 896 ms 3420 KB Output is correct
64 Correct 785 ms 2992 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 847 ms 3276 KB Output is correct
68 Correct 859 ms 5432 KB Output is correct
69 Correct 765 ms 4796 KB Output is correct
70 Correct 842 ms 5276 KB Output is correct
71 Correct 814 ms 5352 KB Output is correct
72 Correct 786 ms 5108 KB Output is correct
73 Correct 782 ms 4984 KB Output is correct
74 Correct 844 ms 5324 KB Output is correct
75 Correct 820 ms 5200 KB Output is correct
76 Correct 867 ms 5496 KB Output is correct
77 Correct 202 ms 5744 KB Output is correct
78 Correct 105 ms 5180 KB Output is correct
79 Correct 147 ms 4848 KB Output is correct
80 Correct 159 ms 5100 KB Output is correct
81 Correct 149 ms 4756 KB Output is correct
82 Correct 139 ms 5480 KB Output is correct
83 Correct 119 ms 5004 KB Output is correct
84 Correct 562 ms 5732 KB Output is correct
85 Correct 906 ms 5716 KB Output is correct
86 Correct 2 ms 296 KB Output is correct
87 Correct 1 ms 212 KB Output is correct
88 Correct 936 ms 5828 KB Output is correct
89 Correct 178 ms 1328 KB Output is correct
90 Correct 1 ms 300 KB Output is correct