답안 #844110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844110 2023-09-05T09:16:04 Z zwezdinv Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 12432 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 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
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 10456 KB Output is correct
2 Correct 24 ms 5468 KB Output is correct
3 Correct 72 ms 10332 KB Output is correct
4 Correct 44 ms 5724 KB Output is correct
5 Correct 82 ms 9820 KB Output is correct
6 Correct 58 ms 9052 KB Output is correct
7 Correct 13 ms 5468 KB Output is correct
8 Correct 55 ms 9052 KB Output is correct
9 Correct 120 ms 7832 KB Output is correct
10 Correct 75 ms 9308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4452 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 4444 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 4440 KB Output is correct
14 Correct 2 ms 4592 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4452 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 3 ms 4444 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 4440 KB Output is correct
14 Correct 2 ms 4592 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 49 ms 5212 KB Output is correct
17 Correct 65 ms 6748 KB Output is correct
18 Correct 168 ms 6740 KB Output is correct
19 Correct 1151 ms 6748 KB Output is correct
20 Correct 1284 ms 6996 KB Output is correct
21 Correct 64 ms 6748 KB Output is correct
22 Correct 5 ms 4444 KB Output is correct
23 Correct 155 ms 5684 KB Output is correct
24 Correct 158 ms 6992 KB Output is correct
25 Correct 36 ms 4700 KB Output is correct
26 Correct 97 ms 5924 KB Output is correct
27 Correct 187 ms 6492 KB Output is correct
28 Correct 169 ms 6996 KB Output is correct
29 Correct 26 ms 5464 KB Output is correct
30 Correct 6 ms 4684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 10456 KB Output is correct
2 Correct 24 ms 5468 KB Output is correct
3 Correct 72 ms 10332 KB Output is correct
4 Correct 44 ms 5724 KB Output is correct
5 Correct 82 ms 9820 KB Output is correct
6 Correct 58 ms 9052 KB Output is correct
7 Correct 13 ms 5468 KB Output is correct
8 Correct 55 ms 9052 KB Output is correct
9 Correct 120 ms 7832 KB Output is correct
10 Correct 75 ms 9308 KB Output is correct
11 Correct 2 ms 4452 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 3 ms 4444 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 4440 KB Output is correct
24 Correct 2 ms 4592 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 49 ms 5212 KB Output is correct
27 Correct 65 ms 6748 KB Output is correct
28 Correct 168 ms 6740 KB Output is correct
29 Correct 1151 ms 6748 KB Output is correct
30 Correct 1284 ms 6996 KB Output is correct
31 Correct 64 ms 6748 KB Output is correct
32 Correct 5 ms 4444 KB Output is correct
33 Correct 155 ms 5684 KB Output is correct
34 Correct 158 ms 6992 KB Output is correct
35 Correct 36 ms 4700 KB Output is correct
36 Correct 97 ms 5924 KB Output is correct
37 Correct 187 ms 6492 KB Output is correct
38 Correct 169 ms 6996 KB Output is correct
39 Correct 26 ms 5464 KB Output is correct
40 Correct 6 ms 4684 KB Output is correct
41 Correct 1922 ms 12368 KB Output is correct
42 Correct 339 ms 12432 KB Output is correct
43 Correct 956 ms 12100 KB Output is correct
44 Correct 335 ms 12116 KB Output is correct
45 Correct 161 ms 12376 KB Output is correct
46 Execution timed out 2060 ms 12380 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 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 97 ms 10456 KB Output is correct
10 Correct 24 ms 5468 KB Output is correct
11 Correct 72 ms 10332 KB Output is correct
12 Correct 44 ms 5724 KB Output is correct
13 Correct 82 ms 9820 KB Output is correct
14 Correct 58 ms 9052 KB Output is correct
15 Correct 13 ms 5468 KB Output is correct
16 Correct 55 ms 9052 KB Output is correct
17 Correct 120 ms 7832 KB Output is correct
18 Correct 75 ms 9308 KB Output is correct
19 Correct 2 ms 4452 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 3 ms 4444 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 4440 KB Output is correct
32 Correct 2 ms 4592 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 49 ms 5212 KB Output is correct
35 Correct 65 ms 6748 KB Output is correct
36 Correct 168 ms 6740 KB Output is correct
37 Correct 1151 ms 6748 KB Output is correct
38 Correct 1284 ms 6996 KB Output is correct
39 Correct 64 ms 6748 KB Output is correct
40 Correct 5 ms 4444 KB Output is correct
41 Correct 155 ms 5684 KB Output is correct
42 Correct 158 ms 6992 KB Output is correct
43 Correct 36 ms 4700 KB Output is correct
44 Correct 97 ms 5924 KB Output is correct
45 Correct 187 ms 6492 KB Output is correct
46 Correct 169 ms 6996 KB Output is correct
47 Correct 26 ms 5464 KB Output is correct
48 Correct 6 ms 4684 KB Output is correct
49 Correct 1922 ms 12368 KB Output is correct
50 Correct 339 ms 12432 KB Output is correct
51 Correct 956 ms 12100 KB Output is correct
52 Correct 335 ms 12116 KB Output is correct
53 Correct 161 ms 12376 KB Output is correct
54 Execution timed out 2060 ms 12380 KB Time limit exceeded
55 Halted 0 ms 0 KB -