답안 #741470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741470 2023-05-14T07:04:24 Z phoebe 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 26188 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define F first
#define S second
#define PB push_back
#define FOR(i, n) for (int i = 0; i < n; i++)

const int maxn = 1e5 + 10, INF = 1e9 + 7;
int block = 224; // sqrt(m)
int n, m, k, c[maxn], tree[maxn * 4];
bool good[maxn] = {0};
unordered_set<int> pos[maxn];
unordered_set<int> can_paint[maxn];

void merge(unordered_set<int> &a, unordered_set<int> &b, int d){
    auto it = a.begin();
    while (it != a.end()){
        if (b.count((*it + d) % m) == 0) a.erase(it++);
        else it++;
    }
}

void update(int x, int v, int tl = 0, int tr = maxn, int i = 1){
    if (tl > x || tr < x) return;
    if (tl == tr){
        tree[i] = v; return;
    }
    int tm = (tl + tr) / 2;
    update(x, v, tl, tm, i * 2); update(x, v, tm + 1, tr, i * 2 + 1);
    tree[i] = min(tree[i * 2], tree[i * 2 + 1]);
}

int range(int l, int r, int tl = 0, int tr = maxn, int i = 1){
    if (tl > r || tr < l) return INF;
    if (l <= tl && tr <= r) return tree[i];
    int tm = (tl + tr) / 2;
    return min(range(l, r, tl, tm, i * 2), 
    range(l, r, tm + 1, tr, i * 2 + 1));
}

int minimumInstructions(int N, int M, int K, 
vector<int> C, vector<int> A, vector<vector<int>> B){
    n = N, m = M, k = K; block = min(block, m);
    FOR(i, n) c[i] = C[i];
    FOR(i, m){
        FOR(j, A[i]) can_paint[B[i][j]].insert(i);
    }
    FOR(i, n){
        for (auto x : can_paint[c[i]]) pos[i].insert(x);
        for (int j = i + 1; j < min(n, i + block); j++){
            merge(pos[i], can_paint[c[j]], j - i);
        }
    }
    FOR(i, n - m + 1){
        int cur = i + block;
        while (cur + block - 1 < i + m){
            merge(pos[i], pos[cur], cur - i);
            cur += block;
        }
        while (cur < i + m){
            merge(pos[i], can_paint[c[cur]], cur - i);
        }
        if (pos[i].size() > 0) good[i] = true;
    }
    // FOR(i, n) cout << good[i] << ' '; cout << endl;
    if (!good[n - m]) return -1;
    fill(tree, tree + maxn * 4, INF);
    update(n - m, 1);
    for (int i = n - m - 1; i >= 0; i--){
        if (!good[i]) continue;
        int best = range(i, i + m);
        update(i, best + 1);
    }
    // FOR(i, n) cout << range(i, i) << ' '; cout << endl;
    int re = range(0, 0);
    return (re < INF ? re : -1);
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12748 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Correct 7 ms 12756 KB Output is correct
5 Correct 7 ms 12884 KB Output is correct
6 Correct 7 ms 12756 KB Output is correct
7 Correct 8 ms 12884 KB Output is correct
8 Correct 8 ms 12884 KB Output is correct
9 Correct 8 ms 12884 KB Output is correct
10 Correct 7 ms 12900 KB Output is correct
11 Correct 6 ms 11220 KB Output is correct
12 Correct 6 ms 11220 KB Output is correct
13 Correct 8 ms 12884 KB Output is correct
14 Correct 8 ms 12884 KB Output is correct
15 Correct 9 ms 12896 KB Output is correct
16 Correct 8 ms 12884 KB Output is correct
17 Correct 8 ms 12976 KB Output is correct
18 Correct 8 ms 12884 KB Output is correct
19 Correct 7 ms 11444 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 7 ms 11348 KB Output is correct
22 Correct 40 ms 26188 KB Output is correct
23 Correct 39 ms 26188 KB Output is correct
24 Correct 40 ms 26092 KB Output is correct
25 Correct 17 ms 15828 KB Output is correct
26 Correct 19 ms 15896 KB Output is correct
27 Correct 14 ms 15524 KB Output is correct
28 Correct 11 ms 13780 KB Output is correct
29 Correct 11 ms 13652 KB Output is correct
30 Correct 11 ms 13652 KB Output is correct
31 Execution timed out 1560 ms 17300 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12748 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Correct 7 ms 12756 KB Output is correct
5 Correct 7 ms 12884 KB Output is correct
6 Correct 7 ms 12756 KB Output is correct
7 Correct 8 ms 12884 KB Output is correct
8 Correct 8 ms 12884 KB Output is correct
9 Correct 8 ms 12884 KB Output is correct
10 Correct 7 ms 12900 KB Output is correct
11 Correct 6 ms 11220 KB Output is correct
12 Correct 6 ms 11220 KB Output is correct
13 Correct 8 ms 12884 KB Output is correct
14 Correct 8 ms 12884 KB Output is correct
15 Correct 9 ms 12896 KB Output is correct
16 Correct 8 ms 12884 KB Output is correct
17 Correct 8 ms 12976 KB Output is correct
18 Correct 8 ms 12884 KB Output is correct
19 Correct 7 ms 11444 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 7 ms 11348 KB Output is correct
22 Correct 6 ms 12756 KB Output is correct
23 Correct 6 ms 11168 KB Output is correct
24 Correct 7 ms 12724 KB Output is correct
25 Correct 6 ms 11220 KB Output is correct
26 Correct 8 ms 12840 KB Output is correct
27 Correct 7 ms 12884 KB Output is correct
28 Correct 13 ms 13192 KB Output is correct
29 Correct 6 ms 11220 KB Output is correct
30 Correct 7 ms 11248 KB Output is correct
31 Correct 10 ms 13012 KB Output is correct
32 Correct 6 ms 11220 KB Output is correct
33 Correct 8 ms 12884 KB Output is correct
34 Correct 9 ms 12936 KB Output is correct
35 Correct 8 ms 12884 KB Output is correct
36 Correct 8 ms 12884 KB Output is correct
37 Correct 8 ms 12884 KB Output is correct
38 Correct 7 ms 11348 KB Output is correct
39 Correct 8 ms 12916 KB Output is correct
40 Correct 6 ms 11348 KB Output is correct
41 Correct 8 ms 12884 KB Output is correct
42 Correct 7 ms 11396 KB Output is correct
43 Correct 8 ms 12884 KB Output is correct
44 Correct 7 ms 12936 KB Output is correct
45 Correct 16 ms 13568 KB Output is correct
46 Correct 7 ms 11348 KB Output is correct
47 Correct 8 ms 11384 KB Output is correct
48 Correct 7 ms 11364 KB Output is correct
49 Correct 8 ms 11476 KB Output is correct
50 Correct 11 ms 12884 KB Output is correct
51 Correct 9 ms 12884 KB Output is correct
52 Correct 8 ms 13040 KB Output is correct
53 Correct 9 ms 13008 KB Output is correct
54 Correct 9 ms 13008 KB Output is correct
55 Correct 9 ms 12884 KB Output is correct
56 Correct 8 ms 11348 KB Output is correct
57 Correct 10 ms 12904 KB Output is correct
58 Correct 7 ms 11348 KB Output is correct
59 Correct 9 ms 12884 KB Output is correct
60 Correct 9 ms 11368 KB Output is correct
61 Correct 9 ms 12896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12756 KB Output is correct
2 Correct 6 ms 11168 KB Output is correct
3 Correct 7 ms 12748 KB Output is correct
4 Correct 7 ms 12756 KB Output is correct
5 Correct 6 ms 11220 KB Output is correct
6 Correct 7 ms 12756 KB Output is correct
7 Correct 7 ms 12884 KB Output is correct
8 Correct 7 ms 12756 KB Output is correct
9 Correct 8 ms 12884 KB Output is correct
10 Correct 8 ms 12884 KB Output is correct
11 Correct 8 ms 12884 KB Output is correct
12 Correct 7 ms 12900 KB Output is correct
13 Correct 6 ms 11220 KB Output is correct
14 Correct 6 ms 11220 KB Output is correct
15 Correct 8 ms 12884 KB Output is correct
16 Correct 8 ms 12884 KB Output is correct
17 Correct 9 ms 12896 KB Output is correct
18 Correct 8 ms 12884 KB Output is correct
19 Correct 8 ms 12976 KB Output is correct
20 Correct 8 ms 12884 KB Output is correct
21 Correct 7 ms 11444 KB Output is correct
22 Correct 8 ms 11348 KB Output is correct
23 Correct 7 ms 11348 KB Output is correct
24 Correct 40 ms 26188 KB Output is correct
25 Correct 39 ms 26188 KB Output is correct
26 Correct 40 ms 26092 KB Output is correct
27 Correct 7 ms 12724 KB Output is correct
28 Correct 6 ms 11220 KB Output is correct
29 Correct 8 ms 12840 KB Output is correct
30 Correct 7 ms 12884 KB Output is correct
31 Correct 13 ms 13192 KB Output is correct
32 Correct 6 ms 11220 KB Output is correct
33 Correct 7 ms 11248 KB Output is correct
34 Correct 10 ms 13012 KB Output is correct
35 Correct 6 ms 11220 KB Output is correct
36 Correct 8 ms 12884 KB Output is correct
37 Correct 9 ms 12936 KB Output is correct
38 Correct 8 ms 12884 KB Output is correct
39 Correct 8 ms 12884 KB Output is correct
40 Correct 8 ms 12884 KB Output is correct
41 Correct 7 ms 11348 KB Output is correct
42 Correct 8 ms 12916 KB Output is correct
43 Correct 6 ms 11348 KB Output is correct
44 Correct 8 ms 12884 KB Output is correct
45 Correct 7 ms 11396 KB Output is correct
46 Correct 8 ms 12884 KB Output is correct
47 Correct 7 ms 12936 KB Output is correct
48 Correct 16 ms 13568 KB Output is correct
49 Correct 7 ms 11348 KB Output is correct
50 Correct 8 ms 11384 KB Output is correct
51 Correct 7 ms 11364 KB Output is correct
52 Correct 8 ms 11476 KB Output is correct
53 Correct 11 ms 12884 KB Output is correct
54 Correct 9 ms 12884 KB Output is correct
55 Correct 8 ms 13040 KB Output is correct
56 Correct 9 ms 13008 KB Output is correct
57 Correct 9 ms 13008 KB Output is correct
58 Correct 9 ms 12884 KB Output is correct
59 Correct 8 ms 11348 KB Output is correct
60 Correct 10 ms 12904 KB Output is correct
61 Correct 7 ms 11348 KB Output is correct
62 Correct 9 ms 12884 KB Output is correct
63 Correct 9 ms 11368 KB Output is correct
64 Correct 9 ms 12896 KB Output is correct
65 Correct 87 ms 14812 KB Output is correct
66 Correct 19 ms 13568 KB Output is correct
67 Correct 107 ms 15172 KB Output is correct
68 Correct 46 ms 14340 KB Output is correct
69 Correct 87 ms 14900 KB Output is correct
70 Correct 25 ms 13500 KB Output is correct
71 Correct 27 ms 13664 KB Output is correct
72 Correct 20 ms 13560 KB Output is correct
73 Correct 10 ms 13396 KB Output is correct
74 Correct 23 ms 13712 KB Output is correct
75 Correct 23 ms 13392 KB Output is correct
76 Correct 53 ms 21884 KB Output is correct
77 Correct 34 ms 23504 KB Output is correct
78 Correct 57 ms 25088 KB Output is correct
79 Correct 235 ms 16880 KB Output is correct
80 Correct 233 ms 16936 KB Output is correct
81 Correct 236 ms 17008 KB Output is correct
82 Correct 237 ms 16948 KB Output is correct
83 Correct 236 ms 17088 KB Output is correct
84 Correct 40 ms 13812 KB Output is correct
85 Correct 46 ms 13772 KB Output is correct
86 Correct 38 ms 13784 KB Output is correct
87 Correct 35 ms 13780 KB Output is correct
88 Correct 36 ms 13764 KB Output is correct
89 Correct 37 ms 13692 KB Output is correct
90 Correct 74 ms 26092 KB Output is correct
91 Correct 61 ms 25964 KB Output is correct
92 Correct 60 ms 26120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12756 KB Output is correct
2 Correct 6 ms 11168 KB Output is correct
3 Correct 7 ms 12748 KB Output is correct
4 Correct 7 ms 12756 KB Output is correct
5 Correct 6 ms 11220 KB Output is correct
6 Correct 7 ms 12756 KB Output is correct
7 Correct 7 ms 12884 KB Output is correct
8 Correct 7 ms 12756 KB Output is correct
9 Correct 8 ms 12884 KB Output is correct
10 Correct 8 ms 12884 KB Output is correct
11 Correct 8 ms 12884 KB Output is correct
12 Correct 7 ms 12900 KB Output is correct
13 Correct 6 ms 11220 KB Output is correct
14 Correct 6 ms 11220 KB Output is correct
15 Correct 8 ms 12884 KB Output is correct
16 Correct 8 ms 12884 KB Output is correct
17 Correct 9 ms 12896 KB Output is correct
18 Correct 8 ms 12884 KB Output is correct
19 Correct 8 ms 12976 KB Output is correct
20 Correct 8 ms 12884 KB Output is correct
21 Correct 7 ms 11444 KB Output is correct
22 Correct 8 ms 11348 KB Output is correct
23 Correct 7 ms 11348 KB Output is correct
24 Correct 40 ms 26188 KB Output is correct
25 Correct 39 ms 26188 KB Output is correct
26 Correct 40 ms 26092 KB Output is correct
27 Correct 17 ms 15828 KB Output is correct
28 Correct 19 ms 15896 KB Output is correct
29 Correct 14 ms 15524 KB Output is correct
30 Correct 11 ms 13780 KB Output is correct
31 Correct 11 ms 13652 KB Output is correct
32 Correct 11 ms 13652 KB Output is correct
33 Execution timed out 1560 ms 17300 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12756 KB Output is correct
2 Correct 6 ms 11168 KB Output is correct
3 Correct 7 ms 12748 KB Output is correct
4 Correct 7 ms 12756 KB Output is correct
5 Correct 6 ms 11220 KB Output is correct
6 Correct 7 ms 12756 KB Output is correct
7 Correct 7 ms 12884 KB Output is correct
8 Correct 7 ms 12756 KB Output is correct
9 Correct 8 ms 12884 KB Output is correct
10 Correct 8 ms 12884 KB Output is correct
11 Correct 8 ms 12884 KB Output is correct
12 Correct 7 ms 12900 KB Output is correct
13 Correct 6 ms 11220 KB Output is correct
14 Correct 6 ms 11220 KB Output is correct
15 Correct 8 ms 12884 KB Output is correct
16 Correct 8 ms 12884 KB Output is correct
17 Correct 9 ms 12896 KB Output is correct
18 Correct 8 ms 12884 KB Output is correct
19 Correct 8 ms 12976 KB Output is correct
20 Correct 8 ms 12884 KB Output is correct
21 Correct 7 ms 11444 KB Output is correct
22 Correct 8 ms 11348 KB Output is correct
23 Correct 7 ms 11348 KB Output is correct
24 Correct 40 ms 26188 KB Output is correct
25 Correct 39 ms 26188 KB Output is correct
26 Correct 40 ms 26092 KB Output is correct
27 Correct 17 ms 15828 KB Output is correct
28 Correct 19 ms 15896 KB Output is correct
29 Correct 14 ms 15524 KB Output is correct
30 Correct 11 ms 13780 KB Output is correct
31 Correct 11 ms 13652 KB Output is correct
32 Correct 11 ms 13652 KB Output is correct
33 Execution timed out 1560 ms 17300 KB Time limit exceeded
34 Halted 0 ms 0 KB -