Submission #397357

# Submission time Handle Problem Language Result Execution time Memory
397357 2021-05-01T23:49:28 Z rocks03 Painting Walls (APIO20_paint) C++14
28 / 100
1231 ms 524292 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
    vector<int> pos[K + 1];
    rep(i, 0, N) pos[C[i]].pb(i);
    vector<int> workers[N + 1];
    rep(i, 0, M){
        for(int col : B[i]){
            for(int p : pos[col]){
                workers[p].pb(i);
            }
        }
    }
    vector<bool> v(N + 1, false);
    vector<pii> work[N + 1];
    for(int x : workers[0]){
        work[0].pb({x, 0});
    }
    rep(y, 1, N + 1){
        for(auto [x, old_y] : work[y - 1]){
            int i = (x + 1) % M, l = y - old_y, j = y;
            if(l == M){
                v[old_y] = true; continue;
            }
            auto it = lower_bound(all(B[i]), C[j]);
            if(it != B[i].end() && *it == C[j]){
                work[y].pb({i, old_y});
            }
        }
        work[y - 1].clear();
        if(y + M - 1 < N){
            for(int x : workers[y]){
                work[y].pb({x, y});
            }
        }
    }
    if(!v[0]) return -1;
    vector<int> dp(N, INT_MAX);
    dp[0] = 1;
    multiset<int> s, ms[N + 1];
    rep(i, 0, N){
        for(int x : ms[i]){
            s.erase(s.find(x));
        }
        if(SZ(s)){
            dp[i] = *s.begin() + 1;
        }
        if(dp[i] == INT_MAX) return -1;
        if(v[i]){
            s.insert(dp[i]);
            int r = min(N - 1, i + M) + 1;
            ms[r].insert(dp[i]);
            if(i + M - 1 >= N - 1) return dp[i];
        }
    }
    return -1;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:34:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         for(auto [x, old_y] : work[y - 1]){
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 4 ms 3404 KB Output is correct
14 Correct 4 ms 3404 KB Output is correct
15 Correct 4 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 15 ms 4044 KB Output is correct
23 Correct 16 ms 4044 KB Output is correct
24 Correct 16 ms 4044 KB Output is correct
25 Correct 10 ms 4684 KB Output is correct
26 Correct 9 ms 4656 KB Output is correct
27 Correct 7 ms 2764 KB Output is correct
28 Correct 7 ms 2764 KB Output is correct
29 Correct 7 ms 2756 KB Output is correct
30 Correct 7 ms 2764 KB Output is correct
31 Correct 697 ms 304476 KB Output is correct
32 Correct 684 ms 304384 KB Output is correct
33 Correct 690 ms 304348 KB Output is correct
34 Correct 689 ms 304452 KB Output is correct
35 Correct 689 ms 304336 KB Output is correct
36 Correct 693 ms 304404 KB Output is correct
37 Correct 27 ms 7060 KB Output is correct
38 Correct 26 ms 7140 KB Output is correct
39 Correct 30 ms 7008 KB Output is correct
40 Correct 41 ms 20364 KB Output is correct
41 Correct 26 ms 12736 KB Output is correct
42 Correct 35 ms 17392 KB Output is correct
43 Correct 22 ms 8524 KB Output is correct
44 Correct 20 ms 7712 KB Output is correct
45 Correct 32 ms 12748 KB Output is correct
46 Runtime error 1103 ms 524292 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 4 ms 3404 KB Output is correct
14 Correct 4 ms 3404 KB Output is correct
15 Correct 4 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 5 ms 2764 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 1 ms 424 KB Output is correct
31 Correct 2 ms 588 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 3 ms 2892 KB Output is correct
34 Correct 3 ms 2380 KB Output is correct
35 Correct 2 ms 1868 KB Output is correct
36 Correct 3 ms 3120 KB Output is correct
37 Correct 3 ms 2508 KB Output is correct
38 Correct 2 ms 2380 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 2 ms 1996 KB Output is correct
41 Correct 1 ms 588 KB Output is correct
42 Correct 2 ms 2508 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 9 ms 4264 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 424 KB Output is correct
50 Correct 4 ms 3404 KB Output is correct
51 Correct 4 ms 3404 KB Output is correct
52 Correct 4 ms 3404 KB Output is correct
53 Correct 4 ms 3404 KB Output is correct
54 Correct 4 ms 3404 KB Output is correct
55 Correct 4 ms 3404 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 2 ms 1072 KB Output is correct
58 Correct 2 ms 2636 KB Output is correct
59 Correct 2 ms 1100 KB Output is correct
60 Correct 2 ms 2636 KB Output is correct
61 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 4 ms 3404 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 15 ms 4044 KB Output is correct
25 Correct 16 ms 4044 KB Output is correct
26 Correct 16 ms 4044 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 5 ms 2764 KB Output is correct
32 Correct 1 ms 428 KB Output is correct
33 Correct 1 ms 424 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 3 ms 2892 KB Output is correct
37 Correct 3 ms 2380 KB Output is correct
38 Correct 2 ms 1868 KB Output is correct
39 Correct 3 ms 3120 KB Output is correct
40 Correct 3 ms 2508 KB Output is correct
41 Correct 2 ms 2380 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 1996 KB Output is correct
44 Correct 1 ms 588 KB Output is correct
45 Correct 2 ms 2508 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 9 ms 4264 KB Output is correct
49 Correct 2 ms 588 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 424 KB Output is correct
53 Correct 4 ms 3404 KB Output is correct
54 Correct 4 ms 3404 KB Output is correct
55 Correct 4 ms 3404 KB Output is correct
56 Correct 4 ms 3404 KB Output is correct
57 Correct 4 ms 3404 KB Output is correct
58 Correct 4 ms 3404 KB Output is correct
59 Correct 2 ms 2636 KB Output is correct
60 Correct 2 ms 1072 KB Output is correct
61 Correct 2 ms 2636 KB Output is correct
62 Correct 2 ms 1100 KB Output is correct
63 Correct 2 ms 2636 KB Output is correct
64 Correct 2 ms 1100 KB Output is correct
65 Correct 41 ms 19460 KB Output is correct
66 Correct 14 ms 7512 KB Output is correct
67 Correct 99 ms 46212 KB Output is correct
68 Correct 40 ms 19268 KB Output is correct
69 Correct 87 ms 38252 KB Output is correct
70 Correct 24 ms 9120 KB Output is correct
71 Correct 25 ms 8784 KB Output is correct
72 Correct 21 ms 6532 KB Output is correct
73 Correct 6 ms 2868 KB Output is correct
74 Correct 22 ms 7708 KB Output is correct
75 Correct 17 ms 6992 KB Output is correct
76 Correct 16 ms 3152 KB Output is correct
77 Correct 18 ms 3660 KB Output is correct
78 Correct 21 ms 4032 KB Output is correct
79 Correct 224 ms 96596 KB Output is correct
80 Correct 208 ms 96636 KB Output is correct
81 Correct 209 ms 96696 KB Output is correct
82 Correct 216 ms 96572 KB Output is correct
83 Correct 216 ms 96828 KB Output is correct
84 Correct 39 ms 13580 KB Output is correct
85 Correct 39 ms 13176 KB Output is correct
86 Correct 38 ms 13124 KB Output is correct
87 Correct 36 ms 12864 KB Output is correct
88 Correct 38 ms 13088 KB Output is correct
89 Correct 38 ms 13380 KB Output is correct
90 Correct 22 ms 4300 KB Output is correct
91 Correct 22 ms 4292 KB Output is correct
92 Correct 23 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 4 ms 3404 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 15 ms 4044 KB Output is correct
25 Correct 16 ms 4044 KB Output is correct
26 Correct 16 ms 4044 KB Output is correct
27 Correct 10 ms 4684 KB Output is correct
28 Correct 9 ms 4656 KB Output is correct
29 Correct 7 ms 2764 KB Output is correct
30 Correct 7 ms 2764 KB Output is correct
31 Correct 7 ms 2756 KB Output is correct
32 Correct 7 ms 2764 KB Output is correct
33 Correct 697 ms 304476 KB Output is correct
34 Correct 684 ms 304384 KB Output is correct
35 Correct 690 ms 304348 KB Output is correct
36 Correct 689 ms 304452 KB Output is correct
37 Correct 689 ms 304336 KB Output is correct
38 Correct 693 ms 304404 KB Output is correct
39 Correct 27 ms 7060 KB Output is correct
40 Correct 26 ms 7140 KB Output is correct
41 Correct 30 ms 7008 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 5 ms 2764 KB Output is correct
47 Correct 1 ms 428 KB Output is correct
48 Correct 1 ms 424 KB Output is correct
49 Correct 2 ms 588 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 3 ms 2892 KB Output is correct
52 Correct 3 ms 2380 KB Output is correct
53 Correct 2 ms 1868 KB Output is correct
54 Correct 3 ms 3120 KB Output is correct
55 Correct 3 ms 2508 KB Output is correct
56 Correct 2 ms 2380 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 2 ms 1996 KB Output is correct
59 Correct 1 ms 588 KB Output is correct
60 Correct 2 ms 2508 KB Output is correct
61 Correct 2 ms 2636 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 9 ms 4264 KB Output is correct
64 Correct 2 ms 588 KB Output is correct
65 Correct 1 ms 460 KB Output is correct
66 Correct 1 ms 460 KB Output is correct
67 Correct 1 ms 424 KB Output is correct
68 Correct 4 ms 3404 KB Output is correct
69 Correct 4 ms 3404 KB Output is correct
70 Correct 4 ms 3404 KB Output is correct
71 Correct 4 ms 3404 KB Output is correct
72 Correct 4 ms 3404 KB Output is correct
73 Correct 4 ms 3404 KB Output is correct
74 Correct 2 ms 2636 KB Output is correct
75 Correct 2 ms 1072 KB Output is correct
76 Correct 2 ms 2636 KB Output is correct
77 Correct 2 ms 1100 KB Output is correct
78 Correct 2 ms 2636 KB Output is correct
79 Correct 2 ms 1100 KB Output is correct
80 Correct 41 ms 19460 KB Output is correct
81 Correct 14 ms 7512 KB Output is correct
82 Correct 99 ms 46212 KB Output is correct
83 Correct 40 ms 19268 KB Output is correct
84 Correct 87 ms 38252 KB Output is correct
85 Correct 24 ms 9120 KB Output is correct
86 Correct 25 ms 8784 KB Output is correct
87 Correct 21 ms 6532 KB Output is correct
88 Correct 6 ms 2868 KB Output is correct
89 Correct 22 ms 7708 KB Output is correct
90 Correct 17 ms 6992 KB Output is correct
91 Correct 16 ms 3152 KB Output is correct
92 Correct 18 ms 3660 KB Output is correct
93 Correct 21 ms 4032 KB Output is correct
94 Correct 224 ms 96596 KB Output is correct
95 Correct 208 ms 96636 KB Output is correct
96 Correct 209 ms 96696 KB Output is correct
97 Correct 216 ms 96572 KB Output is correct
98 Correct 216 ms 96828 KB Output is correct
99 Correct 39 ms 13580 KB Output is correct
100 Correct 39 ms 13176 KB Output is correct
101 Correct 38 ms 13124 KB Output is correct
102 Correct 36 ms 12864 KB Output is correct
103 Correct 38 ms 13088 KB Output is correct
104 Correct 38 ms 13380 KB Output is correct
105 Correct 22 ms 4300 KB Output is correct
106 Correct 22 ms 4292 KB Output is correct
107 Correct 23 ms 4292 KB Output is correct
108 Correct 12 ms 4920 KB Output is correct
109 Runtime error 1231 ms 524288 KB Execution killed with signal 9
110 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 4 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 4 ms 3404 KB Output is correct
20 Correct 4 ms 3404 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 15 ms 4044 KB Output is correct
25 Correct 16 ms 4044 KB Output is correct
26 Correct 16 ms 4044 KB Output is correct
27 Correct 10 ms 4684 KB Output is correct
28 Correct 9 ms 4656 KB Output is correct
29 Correct 7 ms 2764 KB Output is correct
30 Correct 7 ms 2764 KB Output is correct
31 Correct 7 ms 2756 KB Output is correct
32 Correct 7 ms 2764 KB Output is correct
33 Correct 697 ms 304476 KB Output is correct
34 Correct 684 ms 304384 KB Output is correct
35 Correct 690 ms 304348 KB Output is correct
36 Correct 689 ms 304452 KB Output is correct
37 Correct 689 ms 304336 KB Output is correct
38 Correct 693 ms 304404 KB Output is correct
39 Correct 27 ms 7060 KB Output is correct
40 Correct 26 ms 7140 KB Output is correct
41 Correct 30 ms 7008 KB Output is correct
42 Correct 41 ms 20364 KB Output is correct
43 Correct 26 ms 12736 KB Output is correct
44 Correct 35 ms 17392 KB Output is correct
45 Correct 22 ms 8524 KB Output is correct
46 Correct 20 ms 7712 KB Output is correct
47 Correct 32 ms 12748 KB Output is correct
48 Runtime error 1103 ms 524292 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -