Submission #523575

# Submission time Handle Problem Language Result Execution time Memory
523575 2022-02-07T19:53:55 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
70 / 100
952 ms 4980 KB
#include <iostream>
#include <climits>
#include <tuple>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 167171

using namespace std;
using ll = long long;
ll n, k;
tuple<int, int, int, int> R[MN];
ll P[MN], D[MN];
ll P2[MN], D2[MN];
static inline ll calc(ll a, ll b, ll l) {
    if(P[a] == 0 && P[b] == 0)
        return ((D[a] * D[b] + 1) >> 1) * l * l;
    if(P[a]) {
        ll nrseg;
        if((D[a] & 1) == 0) {
            if(P2[b] <= l) nrseg = D2[b] * l + P2[b];
            else nrseg = (D2[b] + 1) * l;
        } else {
            if(P2[b] <= l) nrseg = D2[b] * l;
            else nrseg = (D2[b] - 1) * l + P2[b];
        }
        return calc(a - P[a], b, l) + P[a] * nrseg;
    }
    return calc(b, a, l);
}
ll sol(ll l) {
    for(int i = 1; i <= n; ++i) {
        D[i] = D[i-1];
        P[i] = P[i-1] + 1;
        if(P[i] == l) ++D[i], P[i] = 0;
        D2[i] = D2[i-1];
        P2[i] = P2[i-1] + 1;
        if(P2[i] == (l << 1)) ++D2[i], P2[i] = 0;
    }
    ll arie = ((n / l) * (n / l) + 1) / 2 * l * l, selec;
    for(int i = 1; i <= k; ++i) {
        auto &[a, b, c, d] = R[i];
        selec = calc(c, d, l) + calc(a-1, b-1, l) - calc(c, b-1, l) - calc(a-1, d, l);
        arie += (c - a + 1) * (d - b + 1) - 2 * selec;
    }
    return min(arie, 1ll * n * n - arie);
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    for(int i = 1, a, b, c, d; i <= k; ++i)
        cin >> a >> b >> c >> d, R[i] = make_tuple(a, b, c, d);
    ll re = LLONG_MAX;
    for(int i = 1; i < n; ++i)
        if(n % i == 0) re = min(re, sol(i));
    cout << re << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3252 KB Output is correct
2 Correct 5 ms 972 KB Output is correct
3 Correct 14 ms 3452 KB Output is correct
4 Correct 14 ms 1048 KB Output is correct
5 Correct 17 ms 2944 KB Output is correct
6 Correct 18 ms 2280 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 12 ms 2332 KB Output is correct
9 Correct 28 ms 2636 KB Output is correct
10 Correct 16 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 9 ms 804 KB Output is correct
17 Correct 21 ms 1612 KB Output is correct
18 Correct 34 ms 1892 KB Output is correct
19 Correct 135 ms 1740 KB Output is correct
20 Correct 152 ms 1860 KB Output is correct
21 Correct 19 ms 1612 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 22 ms 1040 KB Output is correct
24 Correct 30 ms 1768 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 22 ms 1268 KB Output is correct
27 Correct 29 ms 1352 KB Output is correct
28 Correct 33 ms 1828 KB Output is correct
29 Correct 8 ms 844 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3252 KB Output is correct
2 Correct 5 ms 972 KB Output is correct
3 Correct 14 ms 3452 KB Output is correct
4 Correct 14 ms 1048 KB Output is correct
5 Correct 17 ms 2944 KB Output is correct
6 Correct 18 ms 2280 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 12 ms 2332 KB Output is correct
9 Correct 28 ms 2636 KB Output is correct
10 Correct 16 ms 2252 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 9 ms 804 KB Output is correct
27 Correct 21 ms 1612 KB Output is correct
28 Correct 34 ms 1892 KB Output is correct
29 Correct 135 ms 1740 KB Output is correct
30 Correct 152 ms 1860 KB Output is correct
31 Correct 19 ms 1612 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 22 ms 1040 KB Output is correct
34 Correct 30 ms 1768 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 22 ms 1268 KB Output is correct
37 Correct 29 ms 1352 KB Output is correct
38 Correct 33 ms 1828 KB Output is correct
39 Correct 8 ms 844 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 154 ms 4712 KB Output is correct
42 Correct 48 ms 4924 KB Output is correct
43 Correct 81 ms 4716 KB Output is correct
44 Correct 49 ms 4852 KB Output is correct
45 Correct 30 ms 4912 KB Output is correct
46 Correct 183 ms 4900 KB Output is correct
47 Correct 26 ms 4684 KB Output is correct
48 Correct 63 ms 4812 KB Output is correct
49 Correct 38 ms 4772 KB Output is correct
50 Correct 839 ms 4340 KB Output is correct
51 Correct 843 ms 4420 KB Output is correct
52 Correct 772 ms 4344 KB Output is correct
53 Correct 849 ms 4428 KB Output is correct
54 Correct 758 ms 4380 KB Output is correct
55 Correct 952 ms 4492 KB Output is correct
56 Correct 774 ms 4268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 20 ms 3252 KB Output is correct
10 Correct 5 ms 972 KB Output is correct
11 Correct 14 ms 3452 KB Output is correct
12 Correct 14 ms 1048 KB Output is correct
13 Correct 17 ms 2944 KB Output is correct
14 Correct 18 ms 2280 KB Output is correct
15 Correct 3 ms 1100 KB Output is correct
16 Correct 12 ms 2332 KB Output is correct
17 Correct 28 ms 2636 KB Output is correct
18 Correct 16 ms 2252 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 804 KB Output is correct
35 Correct 21 ms 1612 KB Output is correct
36 Correct 34 ms 1892 KB Output is correct
37 Correct 135 ms 1740 KB Output is correct
38 Correct 152 ms 1860 KB Output is correct
39 Correct 19 ms 1612 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 22 ms 1040 KB Output is correct
42 Correct 30 ms 1768 KB Output is correct
43 Correct 5 ms 460 KB Output is correct
44 Correct 22 ms 1268 KB Output is correct
45 Correct 29 ms 1352 KB Output is correct
46 Correct 33 ms 1828 KB Output is correct
47 Correct 8 ms 844 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 154 ms 4712 KB Output is correct
50 Correct 48 ms 4924 KB Output is correct
51 Correct 81 ms 4716 KB Output is correct
52 Correct 49 ms 4852 KB Output is correct
53 Correct 30 ms 4912 KB Output is correct
54 Correct 183 ms 4900 KB Output is correct
55 Correct 26 ms 4684 KB Output is correct
56 Correct 63 ms 4812 KB Output is correct
57 Correct 38 ms 4772 KB Output is correct
58 Correct 839 ms 4340 KB Output is correct
59 Correct 843 ms 4420 KB Output is correct
60 Correct 772 ms 4344 KB Output is correct
61 Correct 849 ms 4428 KB Output is correct
62 Correct 758 ms 4380 KB Output is correct
63 Correct 952 ms 4492 KB Output is correct
64 Correct 774 ms 4268 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 851 ms 4384 KB Output is correct
68 Correct 869 ms 4380 KB Output is correct
69 Correct 735 ms 4184 KB Output is correct
70 Correct 776 ms 4324 KB Output is correct
71 Correct 859 ms 4308 KB Output is correct
72 Correct 821 ms 4284 KB Output is correct
73 Correct 783 ms 4256 KB Output is correct
74 Correct 850 ms 4376 KB Output is correct
75 Correct 710 ms 4292 KB Output is correct
76 Correct 791 ms 4460 KB Output is correct
77 Correct 122 ms 4980 KB Output is correct
78 Correct 41 ms 4744 KB Output is correct
79 Correct 85 ms 4772 KB Output is correct
80 Correct 82 ms 4740 KB Output is correct
81 Correct 86 ms 4692 KB Output is correct
82 Correct 79 ms 4932 KB Output is correct
83 Correct 51 ms 4756 KB Output is correct
84 Correct 507 ms 4960 KB Output is correct
85 Correct 822 ms 4476 KB Output is correct
86 Correct 32 ms 2892 KB Output is correct
87 Incorrect 32 ms 2944 KB Output isn't correct
88 Halted 0 ms 0 KB -