Submission #741469

# Submission time Handle Problem Language Result Execution time Memory
741469 2023-05-14T07:02:54 Z phoebe Painting Walls (APIO20_paint) C++17
28 / 100
1500 ms 19148 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};
set<int> pos[maxn];
set<int> can_paint[maxn];

void merge(set<int> &a, 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);
}   
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11236 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 7 ms 11236 KB Output is correct
5 Correct 6 ms 11220 KB Output is correct
6 Correct 6 ms 11220 KB Output is correct
7 Correct 6 ms 11220 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 7 ms 11236 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9704 KB Output is correct
13 Correct 7 ms 11240 KB Output is correct
14 Correct 7 ms 11244 KB Output is correct
15 Correct 7 ms 11348 KB Output is correct
16 Correct 9 ms 11248 KB Output is correct
17 Correct 7 ms 11348 KB Output is correct
18 Correct 8 ms 11348 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9736 KB Output is correct
22 Correct 25 ms 15700 KB Output is correct
23 Correct 33 ms 15752 KB Output is correct
24 Correct 24 ms 15752 KB Output is correct
25 Correct 13 ms 12372 KB Output is correct
26 Correct 13 ms 12372 KB Output is correct
27 Correct 11 ms 11988 KB Output is correct
28 Correct 8 ms 10100 KB Output is correct
29 Correct 8 ms 9940 KB Output is correct
30 Correct 8 ms 9972 KB Output is correct
31 Execution timed out 1589 ms 12212 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11236 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 7 ms 11236 KB Output is correct
5 Correct 6 ms 11220 KB Output is correct
6 Correct 6 ms 11220 KB Output is correct
7 Correct 6 ms 11220 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 7 ms 11236 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9704 KB Output is correct
13 Correct 7 ms 11240 KB Output is correct
14 Correct 7 ms 11244 KB Output is correct
15 Correct 7 ms 11348 KB Output is correct
16 Correct 9 ms 11248 KB Output is correct
17 Correct 7 ms 11348 KB Output is correct
18 Correct 8 ms 11348 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 6 ms 9736 KB Output is correct
22 Correct 6 ms 11176 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 6 ms 11220 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 11220 KB Output is correct
27 Correct 6 ms 11220 KB Output is correct
28 Correct 12 ms 11700 KB Output is correct
29 Correct 6 ms 9684 KB Output is correct
30 Correct 5 ms 9684 KB Output is correct
31 Correct 7 ms 11364 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 8 ms 11220 KB Output is correct
34 Correct 6 ms 11220 KB Output is correct
35 Correct 6 ms 11240 KB Output is correct
36 Correct 6 ms 11244 KB Output is correct
37 Correct 7 ms 11244 KB Output is correct
38 Correct 7 ms 9712 KB Output is correct
39 Correct 6 ms 11220 KB Output is correct
40 Correct 5 ms 9744 KB Output is correct
41 Correct 8 ms 11220 KB Output is correct
42 Correct 6 ms 9720 KB Output is correct
43 Correct 7 ms 11220 KB Output is correct
44 Correct 6 ms 11240 KB Output is correct
45 Correct 17 ms 11916 KB Output is correct
46 Correct 6 ms 9684 KB Output is correct
47 Correct 6 ms 9688 KB Output is correct
48 Correct 6 ms 9640 KB Output is correct
49 Correct 7 ms 9684 KB Output is correct
50 Correct 8 ms 11240 KB Output is correct
51 Correct 7 ms 11348 KB Output is correct
52 Correct 7 ms 11284 KB Output is correct
53 Correct 9 ms 11348 KB Output is correct
54 Correct 7 ms 11348 KB Output is correct
55 Correct 7 ms 11348 KB Output is correct
56 Correct 6 ms 9716 KB Output is correct
57 Correct 7 ms 11348 KB Output is correct
58 Correct 6 ms 9684 KB Output is correct
59 Correct 7 ms 11348 KB Output is correct
60 Correct 7 ms 9684 KB Output is correct
61 Correct 7 ms 11348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11176 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 11236 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 11236 KB Output is correct
7 Correct 6 ms 11220 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 6 ms 11220 KB Output is correct
11 Correct 6 ms 11220 KB Output is correct
12 Correct 7 ms 11236 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9704 KB Output is correct
15 Correct 7 ms 11240 KB Output is correct
16 Correct 7 ms 11244 KB Output is correct
17 Correct 7 ms 11348 KB Output is correct
18 Correct 9 ms 11248 KB Output is correct
19 Correct 7 ms 11348 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9736 KB Output is correct
24 Correct 25 ms 15700 KB Output is correct
25 Correct 33 ms 15752 KB Output is correct
26 Correct 24 ms 15752 KB Output is correct
27 Correct 6 ms 11220 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 6 ms 11220 KB Output is correct
30 Correct 6 ms 11220 KB Output is correct
31 Correct 12 ms 11700 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 7 ms 11364 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 8 ms 11220 KB Output is correct
37 Correct 6 ms 11220 KB Output is correct
38 Correct 6 ms 11240 KB Output is correct
39 Correct 6 ms 11244 KB Output is correct
40 Correct 7 ms 11244 KB Output is correct
41 Correct 7 ms 9712 KB Output is correct
42 Correct 6 ms 11220 KB Output is correct
43 Correct 5 ms 9744 KB Output is correct
44 Correct 8 ms 11220 KB Output is correct
45 Correct 6 ms 9720 KB Output is correct
46 Correct 7 ms 11220 KB Output is correct
47 Correct 6 ms 11240 KB Output is correct
48 Correct 17 ms 11916 KB Output is correct
49 Correct 6 ms 9684 KB Output is correct
50 Correct 6 ms 9688 KB Output is correct
51 Correct 6 ms 9640 KB Output is correct
52 Correct 7 ms 9684 KB Output is correct
53 Correct 8 ms 11240 KB Output is correct
54 Correct 7 ms 11348 KB Output is correct
55 Correct 7 ms 11284 KB Output is correct
56 Correct 9 ms 11348 KB Output is correct
57 Correct 7 ms 11348 KB Output is correct
58 Correct 7 ms 11348 KB Output is correct
59 Correct 6 ms 9716 KB Output is correct
60 Correct 7 ms 11348 KB Output is correct
61 Correct 6 ms 9684 KB Output is correct
62 Correct 7 ms 11348 KB Output is correct
63 Correct 7 ms 9684 KB Output is correct
64 Correct 7 ms 11348 KB Output is correct
65 Correct 200 ms 13472 KB Output is correct
66 Correct 23 ms 12164 KB Output is correct
67 Correct 206 ms 14124 KB Output is correct
68 Correct 72 ms 12852 KB Output is correct
69 Correct 173 ms 13720 KB Output is correct
70 Correct 23 ms 11980 KB Output is correct
71 Correct 26 ms 12240 KB Output is correct
72 Correct 21 ms 12012 KB Output is correct
73 Correct 9 ms 11860 KB Output is correct
74 Correct 24 ms 12044 KB Output is correct
75 Correct 20 ms 11896 KB Output is correct
76 Correct 35 ms 16460 KB Output is correct
77 Correct 26 ms 17136 KB Output is correct
78 Correct 42 ms 18336 KB Output is correct
79 Correct 543 ms 15908 KB Output is correct
80 Correct 537 ms 15932 KB Output is correct
81 Correct 540 ms 15900 KB Output is correct
82 Correct 555 ms 16000 KB Output is correct
83 Correct 536 ms 15944 KB Output is correct
84 Correct 35 ms 12384 KB Output is correct
85 Correct 37 ms 12368 KB Output is correct
86 Correct 38 ms 12252 KB Output is correct
87 Correct 33 ms 12280 KB Output is correct
88 Correct 34 ms 12260 KB Output is correct
89 Correct 34 ms 12240 KB Output is correct
90 Correct 46 ms 19148 KB Output is correct
91 Correct 44 ms 19072 KB Output is correct
92 Correct 46 ms 19044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11176 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 11236 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 11236 KB Output is correct
7 Correct 6 ms 11220 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 6 ms 11220 KB Output is correct
11 Correct 6 ms 11220 KB Output is correct
12 Correct 7 ms 11236 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9704 KB Output is correct
15 Correct 7 ms 11240 KB Output is correct
16 Correct 7 ms 11244 KB Output is correct
17 Correct 7 ms 11348 KB Output is correct
18 Correct 9 ms 11248 KB Output is correct
19 Correct 7 ms 11348 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9736 KB Output is correct
24 Correct 25 ms 15700 KB Output is correct
25 Correct 33 ms 15752 KB Output is correct
26 Correct 24 ms 15752 KB Output is correct
27 Correct 13 ms 12372 KB Output is correct
28 Correct 13 ms 12372 KB Output is correct
29 Correct 11 ms 11988 KB Output is correct
30 Correct 8 ms 10100 KB Output is correct
31 Correct 8 ms 9940 KB Output is correct
32 Correct 8 ms 9972 KB Output is correct
33 Execution timed out 1589 ms 12212 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11176 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 11236 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 11236 KB Output is correct
7 Correct 6 ms 11220 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 6 ms 11220 KB Output is correct
11 Correct 6 ms 11220 KB Output is correct
12 Correct 7 ms 11236 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9704 KB Output is correct
15 Correct 7 ms 11240 KB Output is correct
16 Correct 7 ms 11244 KB Output is correct
17 Correct 7 ms 11348 KB Output is correct
18 Correct 9 ms 11248 KB Output is correct
19 Correct 7 ms 11348 KB Output is correct
20 Correct 8 ms 11348 KB Output is correct
21 Correct 7 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 6 ms 9736 KB Output is correct
24 Correct 25 ms 15700 KB Output is correct
25 Correct 33 ms 15752 KB Output is correct
26 Correct 24 ms 15752 KB Output is correct
27 Correct 13 ms 12372 KB Output is correct
28 Correct 13 ms 12372 KB Output is correct
29 Correct 11 ms 11988 KB Output is correct
30 Correct 8 ms 10100 KB Output is correct
31 Correct 8 ms 9940 KB Output is correct
32 Correct 8 ms 9972 KB Output is correct
33 Execution timed out 1589 ms 12212 KB Time limit exceeded
34 Halted 0 ms 0 KB -