Submission #587500

# Submission time Handle Problem Language Result Execution time Memory
587500 2022-07-02T02:47:24 Z KoD Chessboard (IZhO18_chessboard) C++17
100 / 100
314 ms 4288 KB
#include <bits/stdc++.h>

using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, Q;
    std::cin >> N >> Q;
    vector<int> A(Q), B(Q), C(Q), D(Q);
    for (int i = 0; i < Q; ++i) {
        std::cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i] -= 1;
        B[i] -= 1;
    }
    const auto calc = [&](const int x, const int d) {
        const int q = x / d;
        const int r = x % d;
        if (q % 2 == 0) {
            return r;
        } else {
            return d - r;
        }
    };
    ll ans = (ll)N * N;
    for (int d = 1; d < N; ++d) {
        if (N % d != 0) {
            continue;
        }
        ll sum = 0;
        for (int i = 0; i < Q; ++i) {
            sum += (ll)(calc(C[i], d) - calc(A[i], d)) * (calc(D[i], d) - calc(B[i], d));
        }
        const ll dif = (ll)calc(N, d) * calc(N, d) - 2 * sum;
        ans = std::min(ans, ((ll)N * N - std::abs(dif)) / 2);
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 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 1 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 20 ms 2712 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 12 ms 1876 KB Output is correct
4 Correct 13 ms 1804 KB Output is correct
5 Correct 18 ms 2460 KB Output is correct
6 Correct 12 ms 1632 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 11 ms 1664 KB Output is correct
9 Correct 31 ms 3784 KB Output is correct
10 Correct 18 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 1108 KB Output is correct
17 Correct 24 ms 2900 KB Output is correct
18 Correct 29 ms 3412 KB Output is correct
19 Correct 72 ms 3120 KB Output is correct
20 Correct 77 ms 3472 KB Output is correct
21 Correct 21 ms 2876 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 17 ms 1628 KB Output is correct
24 Correct 27 ms 3152 KB Output is correct
25 Correct 4 ms 584 KB Output is correct
26 Correct 18 ms 2132 KB Output is correct
27 Correct 24 ms 2412 KB Output is correct
28 Correct 28 ms 3368 KB Output is correct
29 Correct 9 ms 1360 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2712 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 12 ms 1876 KB Output is correct
4 Correct 13 ms 1804 KB Output is correct
5 Correct 18 ms 2460 KB Output is correct
6 Correct 12 ms 1632 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 11 ms 1664 KB Output is correct
9 Correct 31 ms 3784 KB Output is correct
10 Correct 18 ms 2288 KB Output is correct
11 Correct 1 ms 260 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 8 ms 1108 KB Output is correct
27 Correct 24 ms 2900 KB Output is correct
28 Correct 29 ms 3412 KB Output is correct
29 Correct 72 ms 3120 KB Output is correct
30 Correct 77 ms 3472 KB Output is correct
31 Correct 21 ms 2876 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 17 ms 1628 KB Output is correct
34 Correct 27 ms 3152 KB Output is correct
35 Correct 4 ms 584 KB Output is correct
36 Correct 18 ms 2132 KB Output is correct
37 Correct 24 ms 2412 KB Output is correct
38 Correct 28 ms 3368 KB Output is correct
39 Correct 9 ms 1360 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 67 ms 3532 KB Output is correct
42 Correct 33 ms 3960 KB Output is correct
43 Correct 45 ms 3624 KB Output is correct
44 Correct 33 ms 3924 KB Output is correct
45 Correct 32 ms 4148 KB Output is correct
46 Correct 75 ms 4000 KB Output is correct
47 Correct 28 ms 3704 KB Output is correct
48 Correct 42 ms 3724 KB Output is correct
49 Correct 30 ms 3552 KB Output is correct
50 Correct 281 ms 4032 KB Output is correct
51 Correct 301 ms 4152 KB Output is correct
52 Correct 279 ms 3884 KB Output is correct
53 Correct 299 ms 4084 KB Output is correct
54 Correct 278 ms 3844 KB Output is correct
55 Correct 314 ms 4172 KB Output is correct
56 Correct 267 ms 3728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 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 1 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 20 ms 2712 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
11 Correct 12 ms 1876 KB Output is correct
12 Correct 13 ms 1804 KB Output is correct
13 Correct 18 ms 2460 KB Output is correct
14 Correct 12 ms 1632 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 11 ms 1664 KB Output is correct
17 Correct 31 ms 3784 KB Output is correct
18 Correct 18 ms 2288 KB Output is correct
19 Correct 1 ms 260 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 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 8 ms 1108 KB Output is correct
35 Correct 24 ms 2900 KB Output is correct
36 Correct 29 ms 3412 KB Output is correct
37 Correct 72 ms 3120 KB Output is correct
38 Correct 77 ms 3472 KB Output is correct
39 Correct 21 ms 2876 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 17 ms 1628 KB Output is correct
42 Correct 27 ms 3152 KB Output is correct
43 Correct 4 ms 584 KB Output is correct
44 Correct 18 ms 2132 KB Output is correct
45 Correct 24 ms 2412 KB Output is correct
46 Correct 28 ms 3368 KB Output is correct
47 Correct 9 ms 1360 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 67 ms 3532 KB Output is correct
50 Correct 33 ms 3960 KB Output is correct
51 Correct 45 ms 3624 KB Output is correct
52 Correct 33 ms 3924 KB Output is correct
53 Correct 32 ms 4148 KB Output is correct
54 Correct 75 ms 4000 KB Output is correct
55 Correct 28 ms 3704 KB Output is correct
56 Correct 42 ms 3724 KB Output is correct
57 Correct 30 ms 3552 KB Output is correct
58 Correct 281 ms 4032 KB Output is correct
59 Correct 301 ms 4152 KB Output is correct
60 Correct 279 ms 3884 KB Output is correct
61 Correct 299 ms 4084 KB Output is correct
62 Correct 278 ms 3844 KB Output is correct
63 Correct 314 ms 4172 KB Output is correct
64 Correct 267 ms 3728 KB Output is correct
65 Correct 0 ms 320 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 301 ms 4032 KB Output is correct
68 Correct 289 ms 4000 KB Output is correct
69 Correct 252 ms 3520 KB Output is correct
70 Correct 287 ms 3936 KB Output is correct
71 Correct 284 ms 3844 KB Output is correct
72 Correct 274 ms 3720 KB Output is correct
73 Correct 268 ms 3688 KB Output is correct
74 Correct 283 ms 3948 KB Output is correct
75 Correct 279 ms 3824 KB Output is correct
76 Correct 295 ms 3960 KB Output is correct
77 Correct 62 ms 4176 KB Output is correct
78 Correct 35 ms 3788 KB Output is correct
79 Correct 48 ms 3668 KB Output is correct
80 Correct 48 ms 3764 KB Output is correct
81 Correct 44 ms 3572 KB Output is correct
82 Correct 44 ms 4108 KB Output is correct
83 Correct 35 ms 3704 KB Output is correct
84 Correct 184 ms 4140 KB Output is correct
85 Correct 303 ms 4184 KB Output is correct
86 Correct 1 ms 324 KB Output is correct
87 Correct 1 ms 320 KB Output is correct
88 Correct 313 ms 4288 KB Output is correct
89 Correct 60 ms 1044 KB Output is correct
90 Correct 1 ms 212 KB Output is correct