Submission #571772

# Submission time Handle Problem Language Result Execution time Memory
571772 2022-06-02T16:59:55 Z SlavicG Painting Walls (APIO20_paint) C++17
28 / 100
1289 ms 524292 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int K = 11;
set<int> st[40001][K];
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
    vector<int> p[k + 1];

    for(int i = 0; i < m; ++i) {
        for(auto x: b[i]) {
            p[x].pb(i);
        }
    }

    
    for(int i = 0; i < n; ++i) {
        for(auto x: p[c[i]]) {
            st[i][0].insert(x);
        }
    }

    for(int j = 1; j < K; ++j) {
        for(int i = 0; i + (1 << j) <= n; ++i) {
            for(auto x: st[i][j - 1]) {
                if(st[i + (1 << (j - 1))][j - 1].count((x + (1 << (j - 1))) % m)) {    
                    st[i][j].insert(x);
                }
            }
        }
    }
    
    vector<bool> can(n, false);

    for(int i = 0; i + m - 1 < n; ++i) {
        for(auto x: p[c[i]]) {
            int cur = x;
            int idx = i;
            bool ok = true;
            for(int j = K - 1; j >= 0; --j) {
                if(m & (1 << j)) {
                    if(!st[idx][j].count(cur)) {
                        ok = false;
                        break;
                    }
                    cur = (cur + (1 << j)) % m;
                    idx += (1 << j);
                }
            }
            if(ok) {
                can[i] = true;
                break;
            }
        }
    }


    set<int> good;
    forn(i, n) if(can[i]) good.insert(i); 
    if(good.empty()) return -1;
    if(!can[0]) return -1;
    int lst = -100000000, ans = 0;
    for(int i = 0; i < n; ++i) {
        if(lst + m - 1 >= i) continue;
        ++ans;
        if(can[i]) {
            lst = i;
        } else {
            auto it = good.lower_bound(i);
            if(it == good.begin()) return -1;
            --it;
            if(*it + m - 1 < i) return -1;
            lst = *it;
        }
    }
    return ans;
}

/*
void solve() {  
    int n, m, k; cin >> n >> m >> k;
    vector<int> c(n); forn(i, n) cin >> c[i];
    vector<int> a(m); forn(i, m) cin >> a[i];
    vector<vector<int>> b(m);
    for(int i = 0; i < m; ++i) {
        b[i].resize(a[i]);
        for(int j = 0; j < a[i]; ++j) {
            cin >> b[i][j];
        }
    }
    cout << minimumInstructions(n, m, k, c, a, b) << "\n";
} 
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/   

# Verdict Execution time Memory Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 11 ms 20968 KB Output is correct
3 Correct 10 ms 20884 KB Output is correct
4 Correct 11 ms 20976 KB Output is correct
5 Correct 11 ms 20968 KB Output is correct
6 Correct 10 ms 20960 KB Output is correct
7 Correct 11 ms 21164 KB Output is correct
8 Correct 12 ms 21076 KB Output is correct
9 Correct 10 ms 20948 KB Output is correct
10 Correct 12 ms 21176 KB Output is correct
11 Correct 12 ms 20976 KB Output is correct
12 Correct 11 ms 20956 KB Output is correct
13 Correct 12 ms 23528 KB Output is correct
14 Correct 13 ms 23508 KB Output is correct
15 Correct 12 ms 23508 KB Output is correct
16 Correct 14 ms 23508 KB Output is correct
17 Correct 12 ms 23532 KB Output is correct
18 Correct 13 ms 23508 KB Output is correct
19 Correct 13 ms 23280 KB Output is correct
20 Correct 17 ms 23280 KB Output is correct
21 Correct 13 ms 23384 KB Output is correct
22 Correct 34 ms 27756 KB Output is correct
23 Correct 33 ms 27724 KB Output is correct
24 Correct 29 ms 27820 KB Output is correct
25 Correct 32 ms 32288 KB Output is correct
26 Correct 39 ms 32204 KB Output is correct
27 Correct 19 ms 23116 KB Output is correct
28 Correct 17 ms 22484 KB Output is correct
29 Correct 16 ms 22228 KB Output is correct
30 Correct 16 ms 22228 KB Output is correct
31 Correct 46 ms 35564 KB Output is correct
32 Correct 39 ms 35632 KB Output is correct
33 Correct 40 ms 35612 KB Output is correct
34 Correct 42 ms 35600 KB Output is correct
35 Correct 39 ms 35588 KB Output is correct
36 Correct 42 ms 35636 KB Output is correct
37 Correct 37 ms 29164 KB Output is correct
38 Correct 36 ms 29132 KB Output is correct
39 Correct 41 ms 29280 KB Output is correct
40 Runtime error 41 ms 47664 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 11 ms 20968 KB Output is correct
3 Correct 10 ms 20884 KB Output is correct
4 Correct 11 ms 20976 KB Output is correct
5 Correct 11 ms 20968 KB Output is correct
6 Correct 10 ms 20960 KB Output is correct
7 Correct 11 ms 21164 KB Output is correct
8 Correct 12 ms 21076 KB Output is correct
9 Correct 10 ms 20948 KB Output is correct
10 Correct 12 ms 21176 KB Output is correct
11 Correct 12 ms 20976 KB Output is correct
12 Correct 11 ms 20956 KB Output is correct
13 Correct 12 ms 23528 KB Output is correct
14 Correct 13 ms 23508 KB Output is correct
15 Correct 12 ms 23508 KB Output is correct
16 Correct 14 ms 23508 KB Output is correct
17 Correct 12 ms 23532 KB Output is correct
18 Correct 13 ms 23508 KB Output is correct
19 Correct 13 ms 23280 KB Output is correct
20 Correct 17 ms 23280 KB Output is correct
21 Correct 13 ms 23384 KB Output is correct
22 Correct 10 ms 20948 KB Output is correct
23 Correct 11 ms 20964 KB Output is correct
24 Correct 11 ms 20976 KB Output is correct
25 Correct 11 ms 20948 KB Output is correct
26 Correct 11 ms 20924 KB Output is correct
27 Correct 12 ms 21152 KB Output is correct
28 Correct 22 ms 24040 KB Output is correct
29 Correct 12 ms 21224 KB Output is correct
30 Correct 12 ms 21220 KB Output is correct
31 Correct 14 ms 22244 KB Output is correct
32 Correct 12 ms 21204 KB Output is correct
33 Correct 12 ms 23096 KB Output is correct
34 Correct 13 ms 22612 KB Output is correct
35 Correct 14 ms 22320 KB Output is correct
36 Correct 12 ms 23380 KB Output is correct
37 Correct 12 ms 22932 KB Output is correct
38 Correct 12 ms 23008 KB Output is correct
39 Correct 11 ms 21076 KB Output is correct
40 Correct 12 ms 22740 KB Output is correct
41 Correct 11 ms 21096 KB Output is correct
42 Correct 13 ms 23216 KB Output is correct
43 Correct 13 ms 23216 KB Output is correct
44 Correct 14 ms 21356 KB Output is correct
45 Correct 26 ms 26724 KB Output is correct
46 Correct 16 ms 21716 KB Output is correct
47 Correct 15 ms 21488 KB Output is correct
48 Correct 12 ms 21332 KB Output is correct
49 Correct 12 ms 21380 KB Output is correct
50 Correct 13 ms 23508 KB Output is correct
51 Correct 12 ms 23508 KB Output is correct
52 Correct 13 ms 23508 KB Output is correct
53 Correct 12 ms 23532 KB Output is correct
54 Correct 13 ms 23560 KB Output is correct
55 Correct 13 ms 23476 KB Output is correct
56 Correct 13 ms 23288 KB Output is correct
57 Correct 13 ms 21204 KB Output is correct
58 Correct 12 ms 23340 KB Output is correct
59 Correct 14 ms 21204 KB Output is correct
60 Correct 12 ms 23280 KB Output is correct
61 Correct 12 ms 21148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 11 ms 20964 KB Output is correct
3 Correct 10 ms 20948 KB Output is correct
4 Correct 11 ms 20968 KB Output is correct
5 Correct 10 ms 20884 KB Output is correct
6 Correct 11 ms 20976 KB Output is correct
7 Correct 11 ms 20968 KB Output is correct
8 Correct 10 ms 20960 KB Output is correct
9 Correct 11 ms 21164 KB Output is correct
10 Correct 12 ms 21076 KB Output is correct
11 Correct 10 ms 20948 KB Output is correct
12 Correct 12 ms 21176 KB Output is correct
13 Correct 12 ms 20976 KB Output is correct
14 Correct 11 ms 20956 KB Output is correct
15 Correct 12 ms 23528 KB Output is correct
16 Correct 13 ms 23508 KB Output is correct
17 Correct 12 ms 23508 KB Output is correct
18 Correct 14 ms 23508 KB Output is correct
19 Correct 12 ms 23532 KB Output is correct
20 Correct 13 ms 23508 KB Output is correct
21 Correct 13 ms 23280 KB Output is correct
22 Correct 17 ms 23280 KB Output is correct
23 Correct 13 ms 23384 KB Output is correct
24 Correct 34 ms 27756 KB Output is correct
25 Correct 33 ms 27724 KB Output is correct
26 Correct 29 ms 27820 KB Output is correct
27 Correct 11 ms 20976 KB Output is correct
28 Correct 11 ms 20948 KB Output is correct
29 Correct 11 ms 20924 KB Output is correct
30 Correct 12 ms 21152 KB Output is correct
31 Correct 22 ms 24040 KB Output is correct
32 Correct 12 ms 21224 KB Output is correct
33 Correct 12 ms 21220 KB Output is correct
34 Correct 14 ms 22244 KB Output is correct
35 Correct 12 ms 21204 KB Output is correct
36 Correct 12 ms 23096 KB Output is correct
37 Correct 13 ms 22612 KB Output is correct
38 Correct 14 ms 22320 KB Output is correct
39 Correct 12 ms 23380 KB Output is correct
40 Correct 12 ms 22932 KB Output is correct
41 Correct 12 ms 23008 KB Output is correct
42 Correct 11 ms 21076 KB Output is correct
43 Correct 12 ms 22740 KB Output is correct
44 Correct 11 ms 21096 KB Output is correct
45 Correct 13 ms 23216 KB Output is correct
46 Correct 13 ms 23216 KB Output is correct
47 Correct 14 ms 21356 KB Output is correct
48 Correct 26 ms 26724 KB Output is correct
49 Correct 16 ms 21716 KB Output is correct
50 Correct 15 ms 21488 KB Output is correct
51 Correct 12 ms 21332 KB Output is correct
52 Correct 12 ms 21380 KB Output is correct
53 Correct 13 ms 23508 KB Output is correct
54 Correct 12 ms 23508 KB Output is correct
55 Correct 13 ms 23508 KB Output is correct
56 Correct 12 ms 23532 KB Output is correct
57 Correct 13 ms 23560 KB Output is correct
58 Correct 13 ms 23476 KB Output is correct
59 Correct 13 ms 23288 KB Output is correct
60 Correct 13 ms 21204 KB Output is correct
61 Correct 12 ms 23340 KB Output is correct
62 Correct 14 ms 21204 KB Output is correct
63 Correct 12 ms 23280 KB Output is correct
64 Correct 12 ms 21148 KB Output is correct
65 Correct 60 ms 36448 KB Output is correct
66 Correct 29 ms 27980 KB Output is correct
67 Correct 87 ms 43688 KB Output is correct
68 Correct 51 ms 34168 KB Output is correct
69 Correct 68 ms 40676 KB Output is correct
70 Correct 22 ms 26288 KB Output is correct
71 Correct 22 ms 26404 KB Output is correct
72 Correct 21 ms 25588 KB Output is correct
73 Correct 20 ms 24844 KB Output is correct
74 Correct 26 ms 26196 KB Output is correct
75 Correct 25 ms 26092 KB Output is correct
76 Correct 34 ms 25824 KB Output is correct
77 Correct 31 ms 26820 KB Output is correct
78 Correct 35 ms 27576 KB Output is correct
79 Correct 118 ms 58436 KB Output is correct
80 Correct 120 ms 58508 KB Output is correct
81 Correct 140 ms 58548 KB Output is correct
82 Correct 125 ms 58456 KB Output is correct
83 Correct 126 ms 58560 KB Output is correct
84 Correct 27 ms 28108 KB Output is correct
85 Correct 25 ms 28052 KB Output is correct
86 Correct 26 ms 28040 KB Output is correct
87 Correct 27 ms 27964 KB Output is correct
88 Correct 26 ms 28044 KB Output is correct
89 Correct 26 ms 28152 KB Output is correct
90 Correct 37 ms 27912 KB Output is correct
91 Correct 39 ms 27880 KB Output is correct
92 Correct 38 ms 27972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 11 ms 20964 KB Output is correct
3 Correct 10 ms 20948 KB Output is correct
4 Correct 11 ms 20968 KB Output is correct
5 Correct 10 ms 20884 KB Output is correct
6 Correct 11 ms 20976 KB Output is correct
7 Correct 11 ms 20968 KB Output is correct
8 Correct 10 ms 20960 KB Output is correct
9 Correct 11 ms 21164 KB Output is correct
10 Correct 12 ms 21076 KB Output is correct
11 Correct 10 ms 20948 KB Output is correct
12 Correct 12 ms 21176 KB Output is correct
13 Correct 12 ms 20976 KB Output is correct
14 Correct 11 ms 20956 KB Output is correct
15 Correct 12 ms 23528 KB Output is correct
16 Correct 13 ms 23508 KB Output is correct
17 Correct 12 ms 23508 KB Output is correct
18 Correct 14 ms 23508 KB Output is correct
19 Correct 12 ms 23532 KB Output is correct
20 Correct 13 ms 23508 KB Output is correct
21 Correct 13 ms 23280 KB Output is correct
22 Correct 17 ms 23280 KB Output is correct
23 Correct 13 ms 23384 KB Output is correct
24 Correct 34 ms 27756 KB Output is correct
25 Correct 33 ms 27724 KB Output is correct
26 Correct 29 ms 27820 KB Output is correct
27 Correct 32 ms 32288 KB Output is correct
28 Correct 39 ms 32204 KB Output is correct
29 Correct 19 ms 23116 KB Output is correct
30 Correct 17 ms 22484 KB Output is correct
31 Correct 16 ms 22228 KB Output is correct
32 Correct 16 ms 22228 KB Output is correct
33 Correct 46 ms 35564 KB Output is correct
34 Correct 39 ms 35632 KB Output is correct
35 Correct 40 ms 35612 KB Output is correct
36 Correct 42 ms 35600 KB Output is correct
37 Correct 39 ms 35588 KB Output is correct
38 Correct 42 ms 35636 KB Output is correct
39 Correct 37 ms 29164 KB Output is correct
40 Correct 36 ms 29132 KB Output is correct
41 Correct 41 ms 29280 KB Output is correct
42 Correct 11 ms 20976 KB Output is correct
43 Correct 11 ms 20948 KB Output is correct
44 Correct 11 ms 20924 KB Output is correct
45 Correct 12 ms 21152 KB Output is correct
46 Correct 22 ms 24040 KB Output is correct
47 Correct 12 ms 21224 KB Output is correct
48 Correct 12 ms 21220 KB Output is correct
49 Correct 14 ms 22244 KB Output is correct
50 Correct 12 ms 21204 KB Output is correct
51 Correct 12 ms 23096 KB Output is correct
52 Correct 13 ms 22612 KB Output is correct
53 Correct 14 ms 22320 KB Output is correct
54 Correct 12 ms 23380 KB Output is correct
55 Correct 12 ms 22932 KB Output is correct
56 Correct 12 ms 23008 KB Output is correct
57 Correct 11 ms 21076 KB Output is correct
58 Correct 12 ms 22740 KB Output is correct
59 Correct 11 ms 21096 KB Output is correct
60 Correct 13 ms 23216 KB Output is correct
61 Correct 13 ms 23216 KB Output is correct
62 Correct 14 ms 21356 KB Output is correct
63 Correct 26 ms 26724 KB Output is correct
64 Correct 16 ms 21716 KB Output is correct
65 Correct 15 ms 21488 KB Output is correct
66 Correct 12 ms 21332 KB Output is correct
67 Correct 12 ms 21380 KB Output is correct
68 Correct 13 ms 23508 KB Output is correct
69 Correct 12 ms 23508 KB Output is correct
70 Correct 13 ms 23508 KB Output is correct
71 Correct 12 ms 23532 KB Output is correct
72 Correct 13 ms 23560 KB Output is correct
73 Correct 13 ms 23476 KB Output is correct
74 Correct 13 ms 23288 KB Output is correct
75 Correct 13 ms 21204 KB Output is correct
76 Correct 12 ms 23340 KB Output is correct
77 Correct 14 ms 21204 KB Output is correct
78 Correct 12 ms 23280 KB Output is correct
79 Correct 12 ms 21148 KB Output is correct
80 Correct 60 ms 36448 KB Output is correct
81 Correct 29 ms 27980 KB Output is correct
82 Correct 87 ms 43688 KB Output is correct
83 Correct 51 ms 34168 KB Output is correct
84 Correct 68 ms 40676 KB Output is correct
85 Correct 22 ms 26288 KB Output is correct
86 Correct 22 ms 26404 KB Output is correct
87 Correct 21 ms 25588 KB Output is correct
88 Correct 20 ms 24844 KB Output is correct
89 Correct 26 ms 26196 KB Output is correct
90 Correct 25 ms 26092 KB Output is correct
91 Correct 34 ms 25824 KB Output is correct
92 Correct 31 ms 26820 KB Output is correct
93 Correct 35 ms 27576 KB Output is correct
94 Correct 118 ms 58436 KB Output is correct
95 Correct 120 ms 58508 KB Output is correct
96 Correct 140 ms 58548 KB Output is correct
97 Correct 125 ms 58456 KB Output is correct
98 Correct 126 ms 58560 KB Output is correct
99 Correct 27 ms 28108 KB Output is correct
100 Correct 25 ms 28052 KB Output is correct
101 Correct 26 ms 28040 KB Output is correct
102 Correct 27 ms 27964 KB Output is correct
103 Correct 26 ms 28044 KB Output is correct
104 Correct 26 ms 28152 KB Output is correct
105 Correct 37 ms 27912 KB Output is correct
106 Correct 39 ms 27880 KB Output is correct
107 Correct 38 ms 27972 KB Output is correct
108 Correct 44 ms 42428 KB Output is correct
109 Runtime error 1289 ms 524292 KB Execution killed with signal 9
110 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20948 KB Output is correct
2 Correct 11 ms 20964 KB Output is correct
3 Correct 10 ms 20948 KB Output is correct
4 Correct 11 ms 20968 KB Output is correct
5 Correct 10 ms 20884 KB Output is correct
6 Correct 11 ms 20976 KB Output is correct
7 Correct 11 ms 20968 KB Output is correct
8 Correct 10 ms 20960 KB Output is correct
9 Correct 11 ms 21164 KB Output is correct
10 Correct 12 ms 21076 KB Output is correct
11 Correct 10 ms 20948 KB Output is correct
12 Correct 12 ms 21176 KB Output is correct
13 Correct 12 ms 20976 KB Output is correct
14 Correct 11 ms 20956 KB Output is correct
15 Correct 12 ms 23528 KB Output is correct
16 Correct 13 ms 23508 KB Output is correct
17 Correct 12 ms 23508 KB Output is correct
18 Correct 14 ms 23508 KB Output is correct
19 Correct 12 ms 23532 KB Output is correct
20 Correct 13 ms 23508 KB Output is correct
21 Correct 13 ms 23280 KB Output is correct
22 Correct 17 ms 23280 KB Output is correct
23 Correct 13 ms 23384 KB Output is correct
24 Correct 34 ms 27756 KB Output is correct
25 Correct 33 ms 27724 KB Output is correct
26 Correct 29 ms 27820 KB Output is correct
27 Correct 32 ms 32288 KB Output is correct
28 Correct 39 ms 32204 KB Output is correct
29 Correct 19 ms 23116 KB Output is correct
30 Correct 17 ms 22484 KB Output is correct
31 Correct 16 ms 22228 KB Output is correct
32 Correct 16 ms 22228 KB Output is correct
33 Correct 46 ms 35564 KB Output is correct
34 Correct 39 ms 35632 KB Output is correct
35 Correct 40 ms 35612 KB Output is correct
36 Correct 42 ms 35600 KB Output is correct
37 Correct 39 ms 35588 KB Output is correct
38 Correct 42 ms 35636 KB Output is correct
39 Correct 37 ms 29164 KB Output is correct
40 Correct 36 ms 29132 KB Output is correct
41 Correct 41 ms 29280 KB Output is correct
42 Runtime error 41 ms 47664 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -