Submission #844109

# Submission time Handle Problem Language Result Execution time Memory
844109 2023-09-05T09:14:39 Z zwezdinv Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 12116 KB
#include<bits/stdc++.h>

using namespace std;
#define all(x) x.begin(), x.end()
using ll = long long;

const int N = 2e5;

int cnt0[4 * N], cnt1[4 * N];
bool upd[4 * N];

void push(int node) {
    if (!upd[node]) return;
    swap(cnt0[node], cnt1[node]);
    upd[node << 1] = !upd[node << 1];
    upd[node << 1 | 1] = !upd[node << 1 | 1];
    upd[node] = 0;
}

int n;

void reset(int node = 1, int l = 0, int r = n - 1) {
    upd[node] = 0;
    if (l == r) {
        cnt0[node] = 1;
        cnt1[node] = 0;
        return;
    }
    int m = (l + r) / 2;
    reset(node << 1, l, m);
    reset(node << 1 | 1, m + 1, r);
    cnt0[node] = cnt0[node << 1] + cnt0[node << 1 | 1];
    cnt1[node] = cnt1[node << 1] + cnt1[node << 1 | 1];
}
void flip(int ql, int qr, int node = 1, int l = 0, int r = n - 1) {
    push(node);
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
        upd[node] = !upd[node];
        push(node);
        return;
    }
    int m = (l + r) / 2;
    flip(ql, qr, node << 1, l, m);
    flip(ql, qr, node << 1 | 1, m + 1, r);
    cnt0[node] = cnt0[node << 1] + cnt0[node << 1 | 1];
    cnt1[node] = cnt1[node << 1] + cnt1[node << 1 | 1];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int k;
    cin >> n >> k;
    vector<vector<pair<int, int>>> ev(n + 1);
    for (int i = 0; i < k; ++i) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        --x1, --y1, --x2, --y2;
        ev[x1].emplace_back(y1, y2);
        ev[x2 + 1].emplace_back(y1, y2);
    }
    ll res = 1e18;
    for (int d = 1; d < n; ++d) {
        if (n % d == 0) {
            {
                ll ans = 0;
                reset();
                for (int i = 0; i < n; i += d * 2) {
                    flip(i, i + d - 1);
                }
                for (int i = 0; i < n; ++i) {
                    if (i % d == 0) {
                        flip(0, n - 1);
                    }
                    for (auto [x, y]: ev[i]) {
                        flip(x, y);
                    }
                    ans += cnt1[1];
                }
                res = min(res, ans);
            }
            {
                ll ans = 0;
                reset();
                for (int i = d; i < n; i += d * 2) {
                    flip(i, i + d - 1);
                }
                for (int i = 0; i < n; ++i) {
                    if (i % d == 0) {
                        flip(0, n - 1);
                    }
                    for (auto [x, y]: ev[i]) {
                        flip(x, y);
                    }
                    ans += cnt1[1];
                }
                res = min(res, ans);
            }
        }
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 10320 KB Output is correct
2 Correct 25 ms 5468 KB Output is correct
3 Correct 84 ms 10392 KB Output is correct
4 Correct 48 ms 5724 KB Output is correct
5 Correct 122 ms 9812 KB Output is correct
6 Correct 61 ms 9168 KB Output is correct
7 Correct 15 ms 5464 KB Output is correct
8 Correct 61 ms 9048 KB Output is correct
9 Correct 136 ms 8020 KB Output is correct
10 Correct 81 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4604 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4604 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 61 ms 5264 KB Output is correct
17 Correct 75 ms 6748 KB Output is correct
18 Correct 198 ms 6748 KB Output is correct
19 Correct 1346 ms 6740 KB Output is correct
20 Correct 1554 ms 6756 KB Output is correct
21 Correct 67 ms 6820 KB Output is correct
22 Correct 7 ms 4700 KB Output is correct
23 Correct 179 ms 5684 KB Output is correct
24 Correct 178 ms 6992 KB Output is correct
25 Correct 38 ms 4696 KB Output is correct
26 Correct 115 ms 5724 KB Output is correct
27 Correct 210 ms 6600 KB Output is correct
28 Correct 186 ms 6748 KB Output is correct
29 Correct 29 ms 5464 KB Output is correct
30 Correct 7 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 10320 KB Output is correct
2 Correct 25 ms 5468 KB Output is correct
3 Correct 84 ms 10392 KB Output is correct
4 Correct 48 ms 5724 KB Output is correct
5 Correct 122 ms 9812 KB Output is correct
6 Correct 61 ms 9168 KB Output is correct
7 Correct 15 ms 5464 KB Output is correct
8 Correct 61 ms 9048 KB Output is correct
9 Correct 136 ms 8020 KB Output is correct
10 Correct 81 ms 9304 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 3 ms 4604 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 3 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 61 ms 5264 KB Output is correct
27 Correct 75 ms 6748 KB Output is correct
28 Correct 198 ms 6748 KB Output is correct
29 Correct 1346 ms 6740 KB Output is correct
30 Correct 1554 ms 6756 KB Output is correct
31 Correct 67 ms 6820 KB Output is correct
32 Correct 7 ms 4700 KB Output is correct
33 Correct 179 ms 5684 KB Output is correct
34 Correct 178 ms 6992 KB Output is correct
35 Correct 38 ms 4696 KB Output is correct
36 Correct 115 ms 5724 KB Output is correct
37 Correct 210 ms 6600 KB Output is correct
38 Correct 186 ms 6748 KB Output is correct
39 Correct 29 ms 5464 KB Output is correct
40 Correct 7 ms 4444 KB Output is correct
41 Execution timed out 2041 ms 12116 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 120 ms 10320 KB Output is correct
10 Correct 25 ms 5468 KB Output is correct
11 Correct 84 ms 10392 KB Output is correct
12 Correct 48 ms 5724 KB Output is correct
13 Correct 122 ms 9812 KB Output is correct
14 Correct 61 ms 9168 KB Output is correct
15 Correct 15 ms 5464 KB Output is correct
16 Correct 61 ms 9048 KB Output is correct
17 Correct 136 ms 8020 KB Output is correct
18 Correct 81 ms 9304 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 3 ms 4604 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 61 ms 5264 KB Output is correct
35 Correct 75 ms 6748 KB Output is correct
36 Correct 198 ms 6748 KB Output is correct
37 Correct 1346 ms 6740 KB Output is correct
38 Correct 1554 ms 6756 KB Output is correct
39 Correct 67 ms 6820 KB Output is correct
40 Correct 7 ms 4700 KB Output is correct
41 Correct 179 ms 5684 KB Output is correct
42 Correct 178 ms 6992 KB Output is correct
43 Correct 38 ms 4696 KB Output is correct
44 Correct 115 ms 5724 KB Output is correct
45 Correct 210 ms 6600 KB Output is correct
46 Correct 186 ms 6748 KB Output is correct
47 Correct 29 ms 5464 KB Output is correct
48 Correct 7 ms 4444 KB Output is correct
49 Execution timed out 2041 ms 12116 KB Time limit exceeded
50 Halted 0 ms 0 KB -