Submission #378573

# Submission time Handle Problem Language Result Execution time Memory
378573 2021-03-17T01:52:46 Z 2qbingxuan Chessboard (IZhO18_chessboard) C++14
100 / 100
1669 ms 4076 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#endif // local

using namespace std;
using ll = int64_t;
const int maxn = 100025;
const ll INF = 9e18;
bool isBlack(int x, int y) {
    return (x + y) & 1;
}

ll calc2d(int x, int y, int k, bool c) {
    if (x < 0 || y < 0) return 0;
    ++x, ++y;
    ll qx = x / k, rx = x % k;
    ll qy = y / k, ry = y % k;
    ll ans = 0;
    ans += ry * k * (isBlack(0, qy) == c ? (qx + 1) / 2 : qx / 2);
    ans += rx * k * (isBlack(qx, 0) == c ? (qy + 1) / 2 : qy / 2);
    ans += 1LL * k * k * (isBlack(0, 0) == c ? (qx * qy + 1) / 2 : qx * qy / 2);
    // debug((isBlack(0, qy+1) == c ? (qx + 1) / 2 : qx / 2));
    debug(rx , k , (isBlack(qx, 0) == c ? (qy + 1) / 2 : qy / 2));
    // debug((isBlack(0, 0) == c ? (qx * qy + 1) / 2 : qx * qy / 2));
    if (isBlack(qx, qy) == c) ans += rx * ry, debug(rx, ry);
    /*
    int res = 0;
    for (int i = 0; i < x; i++)
        for (int j = 0; j < y; j++)
            if (((i / k) + (j / k)) % 2 == c)
                ++res;
    debug(x, y, k, c, ans, res);
    return res;
    */
    return ans;
}
ll calc(int L, vector<tuple<int,int,int,int>> &v, int k) {
    ll res = INF;
    for (int c: {0, 1}) {
        // cerr << "============\n";
        ll ans = calc2d(L-1, L-1, k, c);
        for (auto [lx, ly, rx, ry]: v) {
            debug(lx, ly, rx, ry);
            ans += 1LL * (rx - lx) * (ry - ly);
            ans -= 2LL * (calc2d(rx, ry, k, c) - calc2d(rx, ly, k, c) - calc2d(lx, ry, k, c) + calc2d(lx, ly, k, c));
        }
        debug(ans, k, c);
        res = min(ans, res);
    }
    return res;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int L, n;
    cin >> L >> n;
    vector<tuple<int,int,int,int>> rect(n);
    for (auto &[a, b, c, d]: rect) cin >> a >> b >> c >> d, --a, --b, --a, --b, --c, --d;
    ll ans = INF;
    for (int i = 1; i*i <= L; i++) {
        if (L % i == 0) {
            if (i != L) ans = min(ans, calc(L, rect, i));
            if (L/i != L) ans = min(ans, calc(L, rect, L / i));
        }
        if (i*i > L) break;

    }
    cout << ans << '\n';
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
 */

Compilation message

chessboard.cpp: In function 'll calc(int, std::vector<std::tuple<int, int, int, int> >&, int)':
chessboard.cpp:51:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         for (auto [lx, ly, rx, ry]: v) {
      |                   ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:66:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |     for (auto &[a, b, c, d]: rect) cin >> a >> b >> c >> d, --a, --b, --a, --b, --c, --d;
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1260 KB Output is correct
2 Correct 9 ms 620 KB Output is correct
3 Correct 20 ms 1004 KB Output is correct
4 Correct 22 ms 1004 KB Output is correct
5 Correct 29 ms 1132 KB Output is correct
6 Correct 18 ms 876 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 18 ms 876 KB Output is correct
9 Correct 45 ms 1772 KB Output is correct
10 Correct 28 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 19 ms 748 KB Output is correct
17 Correct 36 ms 1644 KB Output is correct
18 Correct 66 ms 1900 KB Output is correct
19 Correct 307 ms 1772 KB Output is correct
20 Correct 345 ms 1900 KB Output is correct
21 Correct 37 ms 1644 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 50 ms 1004 KB Output is correct
24 Correct 60 ms 1772 KB Output is correct
25 Correct 10 ms 492 KB Output is correct
26 Correct 38 ms 1260 KB Output is correct
27 Correct 64 ms 1388 KB Output is correct
28 Correct 66 ms 1772 KB Output is correct
29 Correct 15 ms 876 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1260 KB Output is correct
2 Correct 9 ms 620 KB Output is correct
3 Correct 20 ms 1004 KB Output is correct
4 Correct 22 ms 1004 KB Output is correct
5 Correct 29 ms 1132 KB Output is correct
6 Correct 18 ms 876 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 18 ms 876 KB Output is correct
9 Correct 45 ms 1772 KB Output is correct
10 Correct 28 ms 1132 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 19 ms 748 KB Output is correct
27 Correct 36 ms 1644 KB Output is correct
28 Correct 66 ms 1900 KB Output is correct
29 Correct 307 ms 1772 KB Output is correct
30 Correct 345 ms 1900 KB Output is correct
31 Correct 37 ms 1644 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 50 ms 1004 KB Output is correct
34 Correct 60 ms 1772 KB Output is correct
35 Correct 10 ms 492 KB Output is correct
36 Correct 38 ms 1260 KB Output is correct
37 Correct 64 ms 1388 KB Output is correct
38 Correct 66 ms 1772 KB Output is correct
39 Correct 15 ms 876 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 274 ms 1644 KB Output is correct
42 Correct 71 ms 1772 KB Output is correct
43 Correct 147 ms 1644 KB Output is correct
44 Correct 70 ms 1772 KB Output is correct
45 Correct 49 ms 1900 KB Output is correct
46 Correct 303 ms 1772 KB Output is correct
47 Correct 43 ms 1644 KB Output is correct
48 Correct 111 ms 1644 KB Output is correct
49 Correct 63 ms 1644 KB Output is correct
50 Correct 1450 ms 1772 KB Output is correct
51 Correct 1546 ms 1900 KB Output is correct
52 Correct 1441 ms 1772 KB Output is correct
53 Correct 1545 ms 1772 KB Output is correct
54 Correct 1421 ms 1772 KB Output is correct
55 Correct 1593 ms 1900 KB Output is correct
56 Correct 1375 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 32 ms 1260 KB Output is correct
10 Correct 9 ms 620 KB Output is correct
11 Correct 20 ms 1004 KB Output is correct
12 Correct 22 ms 1004 KB Output is correct
13 Correct 29 ms 1132 KB Output is correct
14 Correct 18 ms 876 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 18 ms 876 KB Output is correct
17 Correct 45 ms 1772 KB Output is correct
18 Correct 28 ms 1132 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 19 ms 748 KB Output is correct
35 Correct 36 ms 1644 KB Output is correct
36 Correct 66 ms 1900 KB Output is correct
37 Correct 307 ms 1772 KB Output is correct
38 Correct 345 ms 1900 KB Output is correct
39 Correct 37 ms 1644 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 50 ms 1004 KB Output is correct
42 Correct 60 ms 1772 KB Output is correct
43 Correct 10 ms 492 KB Output is correct
44 Correct 38 ms 1260 KB Output is correct
45 Correct 64 ms 1388 KB Output is correct
46 Correct 66 ms 1772 KB Output is correct
47 Correct 15 ms 876 KB Output is correct
48 Correct 2 ms 364 KB Output is correct
49 Correct 274 ms 1644 KB Output is correct
50 Correct 71 ms 1772 KB Output is correct
51 Correct 147 ms 1644 KB Output is correct
52 Correct 70 ms 1772 KB Output is correct
53 Correct 49 ms 1900 KB Output is correct
54 Correct 303 ms 1772 KB Output is correct
55 Correct 43 ms 1644 KB Output is correct
56 Correct 111 ms 1644 KB Output is correct
57 Correct 63 ms 1644 KB Output is correct
58 Correct 1450 ms 1772 KB Output is correct
59 Correct 1546 ms 1900 KB Output is correct
60 Correct 1441 ms 1772 KB Output is correct
61 Correct 1545 ms 1772 KB Output is correct
62 Correct 1421 ms 1772 KB Output is correct
63 Correct 1593 ms 1900 KB Output is correct
64 Correct 1375 ms 1644 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1526 ms 1772 KB Output is correct
68 Correct 1510 ms 1772 KB Output is correct
69 Correct 1325 ms 1644 KB Output is correct
70 Correct 1468 ms 1772 KB Output is correct
71 Correct 1454 ms 1772 KB Output is correct
72 Correct 1404 ms 1644 KB Output is correct
73 Correct 1393 ms 1644 KB Output is correct
74 Correct 1501 ms 1772 KB Output is correct
75 Correct 1435 ms 1644 KB Output is correct
76 Correct 1536 ms 1772 KB Output is correct
77 Correct 224 ms 1900 KB Output is correct
78 Correct 71 ms 1772 KB Output is correct
79 Correct 150 ms 1644 KB Output is correct
80 Correct 161 ms 1772 KB Output is correct
81 Correct 146 ms 1644 KB Output is correct
82 Correct 122 ms 1772 KB Output is correct
83 Correct 101 ms 1644 KB Output is correct
84 Correct 924 ms 1900 KB Output is correct
85 Correct 1637 ms 1900 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 1669 ms 4076 KB Output is correct
89 Correct 318 ms 1132 KB Output is correct
90 Correct 1 ms 364 KB Output is correct