Submission #523577

# Submission time Handle Problem Language Result Execution time Memory
523577 2022-02-07T19:55:35 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
70 / 100
880 ms 4988 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];
ll calc(ll a, ll b, ll l) {
    if(!a || !b) return 0;
    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 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 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 3136 KB Output is correct
2 Correct 5 ms 924 KB Output is correct
3 Correct 13 ms 3568 KB Output is correct
4 Correct 13 ms 1100 KB Output is correct
5 Correct 18 ms 2888 KB Output is correct
6 Correct 16 ms 2380 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 20 ms 2384 KB Output is correct
9 Correct 27 ms 2672 KB Output is correct
10 Correct 21 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 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 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 0 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 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 10 ms 768 KB Output is correct
17 Correct 20 ms 1648 KB Output is correct
18 Correct 48 ms 1860 KB Output is correct
19 Correct 124 ms 1740 KB Output is correct
20 Correct 139 ms 1896 KB Output is correct
21 Correct 20 ms 1580 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 24 ms 972 KB Output is correct
24 Correct 30 ms 1760 KB Output is correct
25 Correct 5 ms 460 KB Output is correct
26 Correct 20 ms 1188 KB Output is correct
27 Correct 28 ms 1356 KB Output is correct
28 Correct 32 ms 1740 KB Output is correct
29 Correct 9 ms 844 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3136 KB Output is correct
2 Correct 5 ms 924 KB Output is correct
3 Correct 13 ms 3568 KB Output is correct
4 Correct 13 ms 1100 KB Output is correct
5 Correct 18 ms 2888 KB Output is correct
6 Correct 16 ms 2380 KB Output is correct
7 Correct 5 ms 1100 KB Output is correct
8 Correct 20 ms 2384 KB Output is correct
9 Correct 27 ms 2672 KB Output is correct
10 Correct 21 ms 2296 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 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 10 ms 768 KB Output is correct
27 Correct 20 ms 1648 KB Output is correct
28 Correct 48 ms 1860 KB Output is correct
29 Correct 124 ms 1740 KB Output is correct
30 Correct 139 ms 1896 KB Output is correct
31 Correct 20 ms 1580 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 24 ms 972 KB Output is correct
34 Correct 30 ms 1760 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 20 ms 1188 KB Output is correct
37 Correct 28 ms 1356 KB Output is correct
38 Correct 32 ms 1740 KB Output is correct
39 Correct 9 ms 844 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 147 ms 4740 KB Output is correct
42 Correct 41 ms 4928 KB Output is correct
43 Correct 84 ms 4752 KB Output is correct
44 Correct 41 ms 4768 KB Output is correct
45 Correct 34 ms 4940 KB Output is correct
46 Correct 162 ms 4892 KB Output is correct
47 Correct 28 ms 4676 KB Output is correct
48 Correct 63 ms 4804 KB Output is correct
49 Correct 36 ms 4764 KB Output is correct
50 Correct 701 ms 4344 KB Output is correct
51 Correct 795 ms 4432 KB Output is correct
52 Correct 750 ms 4420 KB Output is correct
53 Correct 789 ms 4428 KB Output is correct
54 Correct 716 ms 4316 KB Output is correct
55 Correct 822 ms 4488 KB Output is correct
56 Correct 718 ms 4272 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 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 3136 KB Output is correct
10 Correct 5 ms 924 KB Output is correct
11 Correct 13 ms 3568 KB Output is correct
12 Correct 13 ms 1100 KB Output is correct
13 Correct 18 ms 2888 KB Output is correct
14 Correct 16 ms 2380 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 20 ms 2384 KB Output is correct
17 Correct 27 ms 2672 KB Output is correct
18 Correct 21 ms 2296 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 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 10 ms 768 KB Output is correct
35 Correct 20 ms 1648 KB Output is correct
36 Correct 48 ms 1860 KB Output is correct
37 Correct 124 ms 1740 KB Output is correct
38 Correct 139 ms 1896 KB Output is correct
39 Correct 20 ms 1580 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 24 ms 972 KB Output is correct
42 Correct 30 ms 1760 KB Output is correct
43 Correct 5 ms 460 KB Output is correct
44 Correct 20 ms 1188 KB Output is correct
45 Correct 28 ms 1356 KB Output is correct
46 Correct 32 ms 1740 KB Output is correct
47 Correct 9 ms 844 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 147 ms 4740 KB Output is correct
50 Correct 41 ms 4928 KB Output is correct
51 Correct 84 ms 4752 KB Output is correct
52 Correct 41 ms 4768 KB Output is correct
53 Correct 34 ms 4940 KB Output is correct
54 Correct 162 ms 4892 KB Output is correct
55 Correct 28 ms 4676 KB Output is correct
56 Correct 63 ms 4804 KB Output is correct
57 Correct 36 ms 4764 KB Output is correct
58 Correct 701 ms 4344 KB Output is correct
59 Correct 795 ms 4432 KB Output is correct
60 Correct 750 ms 4420 KB Output is correct
61 Correct 789 ms 4428 KB Output is correct
62 Correct 716 ms 4316 KB Output is correct
63 Correct 822 ms 4488 KB Output is correct
64 Correct 718 ms 4272 KB Output is correct
65 Correct 0 ms 332 KB Output is correct
66 Correct 0 ms 332 KB Output is correct
67 Correct 880 ms 4388 KB Output is correct
68 Correct 774 ms 4380 KB Output is correct
69 Correct 657 ms 4160 KB Output is correct
70 Correct 704 ms 4324 KB Output is correct
71 Correct 679 ms 4308 KB Output is correct
72 Correct 657 ms 4252 KB Output is correct
73 Correct 767 ms 4252 KB Output is correct
74 Correct 785 ms 4376 KB Output is correct
75 Correct 680 ms 4292 KB Output is correct
76 Correct 786 ms 4420 KB Output is correct
77 Correct 126 ms 4988 KB Output is correct
78 Correct 40 ms 4772 KB Output is correct
79 Correct 83 ms 4784 KB Output is correct
80 Correct 86 ms 4812 KB Output is correct
81 Correct 79 ms 4732 KB Output is correct
82 Correct 68 ms 4804 KB Output is correct
83 Correct 47 ms 4780 KB Output is correct
84 Correct 426 ms 4960 KB Output is correct
85 Correct 794 ms 4480 KB Output is correct
86 Correct 34 ms 2892 KB Output is correct
87 Incorrect 32 ms 2892 KB Output isn't correct
88 Halted 0 ms 0 KB -