답안 #378571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378571 2021-03-17T01:51:18 Z 2qbingxuan Chessboard (IZhO18_chessboard) C++14
70 / 100
1641 ms 4204 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 = 1e18;
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 += (rx - lx) * (ry - ly);
            ans -= 2 * (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;
      |                ^
# 결과 실행 시간 메모리 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 23 ms 1004 KB Output is correct
5 Correct 28 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 46 ms 1772 KB Output is correct
10 Correct 27 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 20 ms 748 KB Output is correct
17 Correct 39 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 346 ms 1900 KB Output is correct
21 Correct 35 ms 1644 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 49 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 61 ms 1388 KB Output is correct
28 Correct 65 ms 1792 KB Output is correct
29 Correct 15 ms 876 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 23 ms 1004 KB Output is correct
5 Correct 28 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 46 ms 1772 KB Output is correct
10 Correct 27 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 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 20 ms 748 KB Output is correct
27 Correct 39 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 346 ms 1900 KB Output is correct
31 Correct 35 ms 1644 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 49 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 61 ms 1388 KB Output is correct
38 Correct 65 ms 1792 KB Output is correct
39 Correct 15 ms 876 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 268 ms 1644 KB Output is correct
42 Correct 71 ms 1772 KB Output is correct
43 Correct 153 ms 1644 KB Output is correct
44 Correct 69 ms 1772 KB Output is correct
45 Correct 50 ms 1900 KB Output is correct
46 Correct 301 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 65 ms 1792 KB Output is correct
50 Correct 1508 ms 1772 KB Output is correct
51 Correct 1641 ms 1900 KB Output is correct
52 Correct 1481 ms 1772 KB Output is correct
53 Correct 1542 ms 1772 KB Output is correct
54 Correct 1419 ms 1772 KB Output is correct
55 Correct 1598 ms 1900 KB Output is correct
56 Correct 1379 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 23 ms 1004 KB Output is correct
13 Correct 28 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 46 ms 1772 KB Output is correct
18 Correct 27 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 1 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 20 ms 748 KB Output is correct
35 Correct 39 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 346 ms 1900 KB Output is correct
39 Correct 35 ms 1644 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 49 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 61 ms 1388 KB Output is correct
46 Correct 65 ms 1792 KB Output is correct
47 Correct 15 ms 876 KB Output is correct
48 Correct 2 ms 364 KB Output is correct
49 Correct 268 ms 1644 KB Output is correct
50 Correct 71 ms 1772 KB Output is correct
51 Correct 153 ms 1644 KB Output is correct
52 Correct 69 ms 1772 KB Output is correct
53 Correct 50 ms 1900 KB Output is correct
54 Correct 301 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 65 ms 1792 KB Output is correct
58 Correct 1508 ms 1772 KB Output is correct
59 Correct 1641 ms 1900 KB Output is correct
60 Correct 1481 ms 1772 KB Output is correct
61 Correct 1542 ms 1772 KB Output is correct
62 Correct 1419 ms 1772 KB Output is correct
63 Correct 1598 ms 1900 KB Output is correct
64 Correct 1379 ms 1644 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 0 ms 364 KB Output is correct
67 Correct 1535 ms 2284 KB Output is correct
68 Correct 1516 ms 4012 KB Output is correct
69 Correct 1318 ms 3564 KB Output is correct
70 Correct 1477 ms 3948 KB Output is correct
71 Correct 1447 ms 3820 KB Output is correct
72 Correct 1414 ms 3820 KB Output is correct
73 Correct 1385 ms 3692 KB Output is correct
74 Correct 1510 ms 3948 KB Output is correct
75 Correct 1440 ms 3820 KB Output is correct
76 Correct 1542 ms 3948 KB Output is correct
77 Correct 227 ms 4076 KB Output is correct
78 Correct 70 ms 3820 KB Output is correct
79 Correct 153 ms 3692 KB Output is correct
80 Correct 160 ms 3820 KB Output is correct
81 Correct 148 ms 3564 KB Output is correct
82 Correct 123 ms 3948 KB Output is correct
83 Correct 89 ms 3692 KB Output is correct
84 Correct 901 ms 4076 KB Output is correct
85 Correct 1600 ms 4204 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Incorrect 1 ms 364 KB Output isn't correct
88 Halted 0 ms 0 KB -