답안 #523565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523565 2022-02-07T18:53:32 Z RaresFelix Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 7188 KB
#include <vector>
#include <iostream>
#include <climits>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 100071
using ll = long long;
using namespace std;
int n, k;

namespace AINT {
    int V[3 * MN];
    void clear(const int &u = 1, const int &s = 1, const int &d = n) {
        V[u] = 0;
        if(s != d)
            clear(u * 2, s, (s + d) /2), clear(u * 2 + 1, (s + d) / 2 + 1, d);
    }
    static inline void prp(const int &u, const int &s, const int &d) {
        if(!(V[u] & (1 << 30))) return;
        V[u] = (d - s + 1 - (V[u] ^ (1 << 30)));
        if(s != d)
            V[u * 2] ^= 1 << 30, V[u * 2 + 1] ^= 1 << 30;
    }
    void update(const int &l, const int &r, int u = 1, int s = 1, int d = n) {
        prp(u, s, d);
        if(r < s || d < l) return;
        if(l <= s && d <= r) {
            V[u] ^= 1 << 30;
            prp(u, s, d);
            return;
        }
        update(l, r, u * 2, s, (s + d) / 2);
        update(l, r, u * 2 + 1, (s + d) / 2 + 1, d);
        V[u] = (V[u * 2] & 1073741823) + (V[u * 2 + 1] & 1073741823);
    }
}
vector<pair<int, int>> OP[MN];
ll acopera(int l) {
    if(l == n) return LLONG_MAX;
    ///c0 = 1 daca coloram primul patrat
    AINT::clear();
    for(int i = 1 + l; i <= n; i += 2 * l)
        AINT::update(i, i + l - 1);
    ll re = 0;
    for(int i = 1; i <= n; ++i) {
        for(auto [l, r] : OP[i])
            AINT::update(l, r);
        re += AINT::V[1] & 1073741823;
        if(i % l == 0)
            AINT::update(1, n);
    }
    return re;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    ll re = LLONG_MAX;
    for (int i = 1, a, b, c, d; i <= k; ++i) {
        cin >> a >> b >> c >> d;
        OP[a].emplace_back(b, d);
        OP[c + 1].emplace_back(b, d);
    }
    vector<int> D{1};
    for (int i = 2; i * i <= n; ++i)
        if (i * i == n) D.push_back(i);
        else if (n % i == 0)
            D.push_back(i), D.push_back(n / i);
    for (auto it: D) {
        ll v = acopera(it);
        re = min(re, min(v, 1ll * n * n - v));
    }
    cout << re << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 5368 KB Output is correct
2 Correct 18 ms 3372 KB Output is correct
3 Correct 49 ms 5324 KB Output is correct
4 Correct 35 ms 4072 KB Output is correct
5 Correct 64 ms 5100 KB Output is correct
6 Correct 42 ms 4384 KB Output is correct
7 Correct 11 ms 3280 KB Output is correct
8 Correct 40 ms 4484 KB Output is correct
9 Correct 88 ms 5516 KB Output is correct
10 Correct 55 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 34 ms 3368 KB Output is correct
17 Correct 51 ms 4908 KB Output is correct
18 Correct 133 ms 4932 KB Output is correct
19 Correct 682 ms 4848 KB Output is correct
20 Correct 788 ms 4832 KB Output is correct
21 Correct 52 ms 4928 KB Output is correct
22 Correct 4 ms 2636 KB Output is correct
23 Correct 125 ms 3788 KB Output is correct
24 Correct 100 ms 4844 KB Output is correct
25 Correct 21 ms 2892 KB Output is correct
26 Correct 67 ms 4004 KB Output is correct
27 Correct 113 ms 4712 KB Output is correct
28 Correct 116 ms 4844 KB Output is correct
29 Correct 28 ms 3568 KB Output is correct
30 Correct 6 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 5368 KB Output is correct
2 Correct 18 ms 3372 KB Output is correct
3 Correct 49 ms 5324 KB Output is correct
4 Correct 35 ms 4072 KB Output is correct
5 Correct 64 ms 5100 KB Output is correct
6 Correct 42 ms 4384 KB Output is correct
7 Correct 11 ms 3280 KB Output is correct
8 Correct 40 ms 4484 KB Output is correct
9 Correct 88 ms 5516 KB Output is correct
10 Correct 55 ms 4856 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 4 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 34 ms 3368 KB Output is correct
27 Correct 51 ms 4908 KB Output is correct
28 Correct 133 ms 4932 KB Output is correct
29 Correct 682 ms 4848 KB Output is correct
30 Correct 788 ms 4832 KB Output is correct
31 Correct 52 ms 4928 KB Output is correct
32 Correct 4 ms 2636 KB Output is correct
33 Correct 125 ms 3788 KB Output is correct
34 Correct 100 ms 4844 KB Output is correct
35 Correct 21 ms 2892 KB Output is correct
36 Correct 67 ms 4004 KB Output is correct
37 Correct 113 ms 4712 KB Output is correct
38 Correct 116 ms 4844 KB Output is correct
39 Correct 28 ms 3568 KB Output is correct
40 Correct 6 ms 2764 KB Output is correct
41 Correct 1097 ms 6692 KB Output is correct
42 Correct 210 ms 7008 KB Output is correct
43 Correct 618 ms 6696 KB Output is correct
44 Correct 221 ms 6920 KB Output is correct
45 Correct 124 ms 7188 KB Output is correct
46 Correct 1277 ms 6968 KB Output is correct
47 Correct 96 ms 6724 KB Output is correct
48 Correct 408 ms 6812 KB Output is correct
49 Correct 193 ms 6716 KB Output is correct
50 Execution timed out 2079 ms 6804 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 68 ms 5368 KB Output is correct
10 Correct 18 ms 3372 KB Output is correct
11 Correct 49 ms 5324 KB Output is correct
12 Correct 35 ms 4072 KB Output is correct
13 Correct 64 ms 5100 KB Output is correct
14 Correct 42 ms 4384 KB Output is correct
15 Correct 11 ms 3280 KB Output is correct
16 Correct 40 ms 4484 KB Output is correct
17 Correct 88 ms 5516 KB Output is correct
18 Correct 55 ms 4856 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 3 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 4 ms 2636 KB Output is correct
27 Correct 3 ms 2636 KB Output is correct
28 Correct 1 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 3 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 34 ms 3368 KB Output is correct
35 Correct 51 ms 4908 KB Output is correct
36 Correct 133 ms 4932 KB Output is correct
37 Correct 682 ms 4848 KB Output is correct
38 Correct 788 ms 4832 KB Output is correct
39 Correct 52 ms 4928 KB Output is correct
40 Correct 4 ms 2636 KB Output is correct
41 Correct 125 ms 3788 KB Output is correct
42 Correct 100 ms 4844 KB Output is correct
43 Correct 21 ms 2892 KB Output is correct
44 Correct 67 ms 4004 KB Output is correct
45 Correct 113 ms 4712 KB Output is correct
46 Correct 116 ms 4844 KB Output is correct
47 Correct 28 ms 3568 KB Output is correct
48 Correct 6 ms 2764 KB Output is correct
49 Correct 1097 ms 6692 KB Output is correct
50 Correct 210 ms 7008 KB Output is correct
51 Correct 618 ms 6696 KB Output is correct
52 Correct 221 ms 6920 KB Output is correct
53 Correct 124 ms 7188 KB Output is correct
54 Correct 1277 ms 6968 KB Output is correct
55 Correct 96 ms 6724 KB Output is correct
56 Correct 408 ms 6812 KB Output is correct
57 Correct 193 ms 6716 KB Output is correct
58 Execution timed out 2079 ms 6804 KB Time limit exceeded
59 Halted 0 ms 0 KB -