Submission #737653

# Submission time Handle Problem Language Result Execution time Memory
737653 2023-05-07T13:24:26 Z Abrar_Al_Samit Painting Walls (APIO20_paint) C++17
51 / 100
492 ms 524288 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;



const int nax = 1e5;


vector<int> col_to_wall[nax], cand[nax];
vector<bitset<nax/2>>is(nax/2);
bool good[nax];
bool on[nax];

int minimumInstructions(
    int N, int M, int K, vector<int> C,
    vector<int> A, vector<vector<int>> B) {

    
    for(int i=0; i<N; ++i) {
        col_to_wall[C[i]].push_back(i);
    }

    for(int i=0; i<M; ++i) {
        for(int j=0; j<A[i]; ++j) {
            for(int x : col_to_wall[B[i][j]]) {
                cand[x].push_back(i);
                is[x][i] = 1;
            }
        }
    }

    int prev_succ = -1;
    for(int i=0; i<=N-M; ++i) {
        int cur_succ = -1;
        for(int j : cand[i]) {

            int pre_tag = (j-1+M)%M;
            bool yasss = true;


            if(pre_tag==prev_succ) {
                if(i+M-1<nax/2) {
                    if(is[i+M-1][pre_tag]) {
                        cur_succ = j;
                        break;
                    } else continue;
                } else {
                    if(binary_search(cand[i+M-1].begin(), cand[i+M-1].end(), pre_tag)) {
                        cur_succ = j;
                        break;
                    } else continue;
                }
            } else if(on[pre_tag]) {
                continue;
            }

            for(int l=1, cr=j+1; l<M; ++l, ++cr) {
                if(cr==M) cr = 0;

                if(i+l<nax/2) yasss &= is[i+l][cr];
                else yasss &= binary_search(cand[i+l].begin(), cand[i+l].end(), cr);

                if(!yasss) break;
            }
            if(yasss) {
                cur_succ = j;
                break;
            }
        }
        if(i) {
            for(int x : cand[i-1]) {
                if(x==prev_succ) break;
                on[x] = 0;
            }
        }
        for(int x : cand[i]) {
            if(x==cur_succ) break;
            on[x] = 1;
        }

        prev_succ = cur_succ;
        if(cur_succ!=-1) {
            good[i] = 1;
        }
    }


    if(!good[0]) return -1;
    int last = 0, pending = -1;

    int ans = 1;
    for(int i=1; i<N; ++i) {
        if(good[i]) {
            pending = i;
        }
        if(last+M==i) {
            if(pending==-1) return -1;
            last = pending;
            pending = -1;
            ++ans;
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 127 ms 310988 KB Output is correct
2 Correct 134 ms 310976 KB Output is correct
3 Correct 117 ms 311032 KB Output is correct
4 Correct 125 ms 311024 KB Output is correct
5 Correct 153 ms 311012 KB Output is correct
6 Correct 127 ms 310984 KB Output is correct
7 Correct 124 ms 311008 KB Output is correct
8 Correct 125 ms 310988 KB Output is correct
9 Correct 131 ms 311092 KB Output is correct
10 Correct 137 ms 311056 KB Output is correct
11 Correct 134 ms 310968 KB Output is correct
12 Correct 118 ms 310988 KB Output is correct
13 Correct 133 ms 311056 KB Output is correct
14 Correct 125 ms 311116 KB Output is correct
15 Correct 125 ms 311168 KB Output is correct
16 Correct 131 ms 311064 KB Output is correct
17 Correct 160 ms 311072 KB Output is correct
18 Correct 141 ms 311048 KB Output is correct
19 Correct 135 ms 311104 KB Output is correct
20 Correct 132 ms 311040 KB Output is correct
21 Correct 128 ms 310988 KB Output is correct
22 Correct 126 ms 312448 KB Output is correct
23 Correct 129 ms 312472 KB Output is correct
24 Correct 135 ms 312376 KB Output is correct
25 Correct 133 ms 311896 KB Output is correct
26 Correct 132 ms 311876 KB Output is correct
27 Correct 130 ms 311972 KB Output is correct
28 Correct 146 ms 312004 KB Output is correct
29 Correct 128 ms 311908 KB Output is correct
30 Correct 137 ms 312076 KB Output is correct
31 Correct 132 ms 312920 KB Output is correct
32 Correct 144 ms 313052 KB Output is correct
33 Correct 145 ms 312992 KB Output is correct
34 Correct 186 ms 312980 KB Output is correct
35 Correct 143 ms 312920 KB Output is correct
36 Correct 151 ms 312984 KB Output is correct
37 Correct 147 ms 313988 KB Output is correct
38 Correct 156 ms 314032 KB Output is correct
39 Correct 143 ms 313952 KB Output is correct
40 Runtime error 492 ms 524288 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 127 ms 310988 KB Output is correct
2 Correct 134 ms 310976 KB Output is correct
3 Correct 117 ms 311032 KB Output is correct
4 Correct 125 ms 311024 KB Output is correct
5 Correct 153 ms 311012 KB Output is correct
6 Correct 127 ms 310984 KB Output is correct
7 Correct 124 ms 311008 KB Output is correct
8 Correct 125 ms 310988 KB Output is correct
9 Correct 131 ms 311092 KB Output is correct
10 Correct 137 ms 311056 KB Output is correct
11 Correct 134 ms 310968 KB Output is correct
12 Correct 118 ms 310988 KB Output is correct
13 Correct 133 ms 311056 KB Output is correct
14 Correct 125 ms 311116 KB Output is correct
15 Correct 125 ms 311168 KB Output is correct
16 Correct 131 ms 311064 KB Output is correct
17 Correct 160 ms 311072 KB Output is correct
18 Correct 141 ms 311048 KB Output is correct
19 Correct 135 ms 311104 KB Output is correct
20 Correct 132 ms 311040 KB Output is correct
21 Correct 128 ms 310988 KB Output is correct
22 Correct 154 ms 311060 KB Output is correct
23 Correct 143 ms 310968 KB Output is correct
24 Correct 134 ms 311004 KB Output is correct
25 Correct 131 ms 311008 KB Output is correct
26 Correct 120 ms 311016 KB Output is correct
27 Correct 127 ms 311080 KB Output is correct
28 Correct 127 ms 311044 KB Output is correct
29 Correct 134 ms 311020 KB Output is correct
30 Correct 146 ms 311044 KB Output is correct
31 Correct 135 ms 311072 KB Output is correct
32 Correct 136 ms 311120 KB Output is correct
33 Correct 123 ms 311064 KB Output is correct
34 Correct 121 ms 311000 KB Output is correct
35 Correct 128 ms 311116 KB Output is correct
36 Correct 155 ms 311052 KB Output is correct
37 Correct 127 ms 311000 KB Output is correct
38 Correct 125 ms 311004 KB Output is correct
39 Correct 145 ms 311068 KB Output is correct
40 Correct 127 ms 311072 KB Output is correct
41 Correct 131 ms 311068 KB Output is correct
42 Correct 125 ms 310980 KB Output is correct
43 Correct 141 ms 310988 KB Output is correct
44 Correct 141 ms 311060 KB Output is correct
45 Correct 129 ms 311100 KB Output is correct
46 Correct 122 ms 311144 KB Output is correct
47 Correct 137 ms 311132 KB Output is correct
48 Correct 124 ms 311068 KB Output is correct
49 Correct 131 ms 311012 KB Output is correct
50 Correct 156 ms 311048 KB Output is correct
51 Correct 122 ms 311064 KB Output is correct
52 Correct 120 ms 311072 KB Output is correct
53 Correct 127 ms 311088 KB Output is correct
54 Correct 120 ms 311060 KB Output is correct
55 Correct 142 ms 311012 KB Output is correct
56 Correct 124 ms 311232 KB Output is correct
57 Correct 122 ms 311072 KB Output is correct
58 Correct 132 ms 311020 KB Output is correct
59 Correct 149 ms 311064 KB Output is correct
60 Correct 127 ms 310988 KB Output is correct
61 Correct 126 ms 311004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 311060 KB Output is correct
2 Correct 143 ms 310968 KB Output is correct
3 Correct 127 ms 310988 KB Output is correct
4 Correct 134 ms 310976 KB Output is correct
5 Correct 117 ms 311032 KB Output is correct
6 Correct 125 ms 311024 KB Output is correct
7 Correct 153 ms 311012 KB Output is correct
8 Correct 127 ms 310984 KB Output is correct
9 Correct 124 ms 311008 KB Output is correct
10 Correct 125 ms 310988 KB Output is correct
11 Correct 131 ms 311092 KB Output is correct
12 Correct 137 ms 311056 KB Output is correct
13 Correct 134 ms 310968 KB Output is correct
14 Correct 118 ms 310988 KB Output is correct
15 Correct 133 ms 311056 KB Output is correct
16 Correct 125 ms 311116 KB Output is correct
17 Correct 125 ms 311168 KB Output is correct
18 Correct 131 ms 311064 KB Output is correct
19 Correct 160 ms 311072 KB Output is correct
20 Correct 141 ms 311048 KB Output is correct
21 Correct 135 ms 311104 KB Output is correct
22 Correct 132 ms 311040 KB Output is correct
23 Correct 128 ms 310988 KB Output is correct
24 Correct 126 ms 312448 KB Output is correct
25 Correct 129 ms 312472 KB Output is correct
26 Correct 135 ms 312376 KB Output is correct
27 Correct 134 ms 311004 KB Output is correct
28 Correct 131 ms 311008 KB Output is correct
29 Correct 120 ms 311016 KB Output is correct
30 Correct 127 ms 311080 KB Output is correct
31 Correct 127 ms 311044 KB Output is correct
32 Correct 134 ms 311020 KB Output is correct
33 Correct 146 ms 311044 KB Output is correct
34 Correct 135 ms 311072 KB Output is correct
35 Correct 136 ms 311120 KB Output is correct
36 Correct 123 ms 311064 KB Output is correct
37 Correct 121 ms 311000 KB Output is correct
38 Correct 128 ms 311116 KB Output is correct
39 Correct 155 ms 311052 KB Output is correct
40 Correct 127 ms 311000 KB Output is correct
41 Correct 125 ms 311004 KB Output is correct
42 Correct 145 ms 311068 KB Output is correct
43 Correct 127 ms 311072 KB Output is correct
44 Correct 131 ms 311068 KB Output is correct
45 Correct 125 ms 310980 KB Output is correct
46 Correct 141 ms 310988 KB Output is correct
47 Correct 141 ms 311060 KB Output is correct
48 Correct 129 ms 311100 KB Output is correct
49 Correct 122 ms 311144 KB Output is correct
50 Correct 137 ms 311132 KB Output is correct
51 Correct 124 ms 311068 KB Output is correct
52 Correct 131 ms 311012 KB Output is correct
53 Correct 156 ms 311048 KB Output is correct
54 Correct 122 ms 311064 KB Output is correct
55 Correct 120 ms 311072 KB Output is correct
56 Correct 127 ms 311088 KB Output is correct
57 Correct 120 ms 311060 KB Output is correct
58 Correct 142 ms 311012 KB Output is correct
59 Correct 124 ms 311232 KB Output is correct
60 Correct 122 ms 311072 KB Output is correct
61 Correct 132 ms 311020 KB Output is correct
62 Correct 149 ms 311064 KB Output is correct
63 Correct 127 ms 310988 KB Output is correct
64 Correct 126 ms 311004 KB Output is correct
65 Correct 157 ms 311300 KB Output is correct
66 Correct 133 ms 311228 KB Output is correct
67 Correct 139 ms 311336 KB Output is correct
68 Correct 139 ms 311316 KB Output is correct
69 Correct 124 ms 311212 KB Output is correct
70 Correct 128 ms 311240 KB Output is correct
71 Correct 161 ms 311304 KB Output is correct
72 Correct 147 ms 311228 KB Output is correct
73 Correct 142 ms 311144 KB Output is correct
74 Correct 127 ms 311212 KB Output is correct
75 Correct 133 ms 311188 KB Output is correct
76 Correct 148 ms 312584 KB Output is correct
77 Correct 138 ms 312744 KB Output is correct
78 Correct 143 ms 312964 KB Output is correct
79 Correct 135 ms 311608 KB Output is correct
80 Correct 129 ms 311520 KB Output is correct
81 Correct 167 ms 311684 KB Output is correct
82 Correct 126 ms 311576 KB Output is correct
83 Correct 120 ms 311500 KB Output is correct
84 Correct 119 ms 311348 KB Output is correct
85 Correct 130 ms 311312 KB Output is correct
86 Correct 122 ms 311320 KB Output is correct
87 Correct 127 ms 311348 KB Output is correct
88 Correct 121 ms 311372 KB Output is correct
89 Correct 126 ms 311376 KB Output is correct
90 Correct 157 ms 313164 KB Output is correct
91 Correct 140 ms 313120 KB Output is correct
92 Correct 141 ms 313268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 311060 KB Output is correct
2 Correct 143 ms 310968 KB Output is correct
3 Correct 127 ms 310988 KB Output is correct
4 Correct 134 ms 310976 KB Output is correct
5 Correct 117 ms 311032 KB Output is correct
6 Correct 125 ms 311024 KB Output is correct
7 Correct 153 ms 311012 KB Output is correct
8 Correct 127 ms 310984 KB Output is correct
9 Correct 124 ms 311008 KB Output is correct
10 Correct 125 ms 310988 KB Output is correct
11 Correct 131 ms 311092 KB Output is correct
12 Correct 137 ms 311056 KB Output is correct
13 Correct 134 ms 310968 KB Output is correct
14 Correct 118 ms 310988 KB Output is correct
15 Correct 133 ms 311056 KB Output is correct
16 Correct 125 ms 311116 KB Output is correct
17 Correct 125 ms 311168 KB Output is correct
18 Correct 131 ms 311064 KB Output is correct
19 Correct 160 ms 311072 KB Output is correct
20 Correct 141 ms 311048 KB Output is correct
21 Correct 135 ms 311104 KB Output is correct
22 Correct 132 ms 311040 KB Output is correct
23 Correct 128 ms 310988 KB Output is correct
24 Correct 126 ms 312448 KB Output is correct
25 Correct 129 ms 312472 KB Output is correct
26 Correct 135 ms 312376 KB Output is correct
27 Correct 133 ms 311896 KB Output is correct
28 Correct 132 ms 311876 KB Output is correct
29 Correct 130 ms 311972 KB Output is correct
30 Correct 146 ms 312004 KB Output is correct
31 Correct 128 ms 311908 KB Output is correct
32 Correct 137 ms 312076 KB Output is correct
33 Correct 132 ms 312920 KB Output is correct
34 Correct 144 ms 313052 KB Output is correct
35 Correct 145 ms 312992 KB Output is correct
36 Correct 186 ms 312980 KB Output is correct
37 Correct 143 ms 312920 KB Output is correct
38 Correct 151 ms 312984 KB Output is correct
39 Correct 147 ms 313988 KB Output is correct
40 Correct 156 ms 314032 KB Output is correct
41 Correct 143 ms 313952 KB Output is correct
42 Correct 134 ms 311004 KB Output is correct
43 Correct 131 ms 311008 KB Output is correct
44 Correct 120 ms 311016 KB Output is correct
45 Correct 127 ms 311080 KB Output is correct
46 Correct 127 ms 311044 KB Output is correct
47 Correct 134 ms 311020 KB Output is correct
48 Correct 146 ms 311044 KB Output is correct
49 Correct 135 ms 311072 KB Output is correct
50 Correct 136 ms 311120 KB Output is correct
51 Correct 123 ms 311064 KB Output is correct
52 Correct 121 ms 311000 KB Output is correct
53 Correct 128 ms 311116 KB Output is correct
54 Correct 155 ms 311052 KB Output is correct
55 Correct 127 ms 311000 KB Output is correct
56 Correct 125 ms 311004 KB Output is correct
57 Correct 145 ms 311068 KB Output is correct
58 Correct 127 ms 311072 KB Output is correct
59 Correct 131 ms 311068 KB Output is correct
60 Correct 125 ms 310980 KB Output is correct
61 Correct 141 ms 310988 KB Output is correct
62 Correct 141 ms 311060 KB Output is correct
63 Correct 129 ms 311100 KB Output is correct
64 Correct 122 ms 311144 KB Output is correct
65 Correct 137 ms 311132 KB Output is correct
66 Correct 124 ms 311068 KB Output is correct
67 Correct 131 ms 311012 KB Output is correct
68 Correct 156 ms 311048 KB Output is correct
69 Correct 122 ms 311064 KB Output is correct
70 Correct 120 ms 311072 KB Output is correct
71 Correct 127 ms 311088 KB Output is correct
72 Correct 120 ms 311060 KB Output is correct
73 Correct 142 ms 311012 KB Output is correct
74 Correct 124 ms 311232 KB Output is correct
75 Correct 122 ms 311072 KB Output is correct
76 Correct 132 ms 311020 KB Output is correct
77 Correct 149 ms 311064 KB Output is correct
78 Correct 127 ms 310988 KB Output is correct
79 Correct 126 ms 311004 KB Output is correct
80 Correct 157 ms 311300 KB Output is correct
81 Correct 133 ms 311228 KB Output is correct
82 Correct 139 ms 311336 KB Output is correct
83 Correct 139 ms 311316 KB Output is correct
84 Correct 124 ms 311212 KB Output is correct
85 Correct 128 ms 311240 KB Output is correct
86 Correct 161 ms 311304 KB Output is correct
87 Correct 147 ms 311228 KB Output is correct
88 Correct 142 ms 311144 KB Output is correct
89 Correct 127 ms 311212 KB Output is correct
90 Correct 133 ms 311188 KB Output is correct
91 Correct 148 ms 312584 KB Output is correct
92 Correct 138 ms 312744 KB Output is correct
93 Correct 143 ms 312964 KB Output is correct
94 Correct 135 ms 311608 KB Output is correct
95 Correct 129 ms 311520 KB Output is correct
96 Correct 167 ms 311684 KB Output is correct
97 Correct 126 ms 311576 KB Output is correct
98 Correct 120 ms 311500 KB Output is correct
99 Correct 119 ms 311348 KB Output is correct
100 Correct 130 ms 311312 KB Output is correct
101 Correct 122 ms 311320 KB Output is correct
102 Correct 127 ms 311348 KB Output is correct
103 Correct 121 ms 311372 KB Output is correct
104 Correct 126 ms 311376 KB Output is correct
105 Correct 157 ms 313164 KB Output is correct
106 Correct 140 ms 313120 KB Output is correct
107 Correct 141 ms 313268 KB Output is correct
108 Correct 146 ms 311948 KB Output is correct
109 Correct 331 ms 369900 KB Output is correct
110 Correct 322 ms 336144 KB Output is correct
111 Correct 263 ms 334644 KB Output is correct
112 Correct 303 ms 342504 KB Output is correct
113 Correct 225 ms 326604 KB Output is correct
114 Correct 148 ms 312972 KB Output is correct
115 Correct 146 ms 312900 KB Output is correct
116 Correct 155 ms 313444 KB Output is correct
117 Correct 164 ms 312860 KB Output is correct
118 Correct 145 ms 313132 KB Output is correct
119 Correct 135 ms 312780 KB Output is correct
120 Correct 129 ms 313164 KB Output is correct
121 Correct 131 ms 312080 KB Output is correct
122 Correct 154 ms 313544 KB Output is correct
123 Correct 158 ms 312028 KB Output is correct
124 Correct 143 ms 313932 KB Output is correct
125 Correct 137 ms 312528 KB Output is correct
126 Correct 135 ms 312512 KB Output is correct
127 Correct 162 ms 312884 KB Output is correct
128 Correct 146 ms 312356 KB Output is correct
129 Correct 151 ms 312460 KB Output is correct
130 Correct 138 ms 312016 KB Output is correct
131 Correct 443 ms 392012 KB Output is correct
132 Correct 442 ms 351968 KB Output is correct
133 Correct 395 ms 351928 KB Output is correct
134 Correct 386 ms 352100 KB Output is correct
135 Correct 385 ms 348024 KB Output is correct
136 Correct 160 ms 313804 KB Output is correct
137 Correct 141 ms 313812 KB Output is correct
138 Correct 155 ms 313804 KB Output is correct
139 Correct 140 ms 313836 KB Output is correct
140 Correct 140 ms 313784 KB Output is correct
141 Correct 144 ms 313808 KB Output is correct
142 Correct 147 ms 314760 KB Output is correct
143 Correct 135 ms 312780 KB Output is correct
144 Correct 163 ms 314600 KB Output is correct
145 Correct 139 ms 312720 KB Output is correct
146 Correct 160 ms 314664 KB Output is correct
147 Correct 129 ms 312780 KB Output is correct
148 Correct 147 ms 313284 KB Output is correct
149 Correct 131 ms 313108 KB Output is correct
150 Correct 136 ms 313032 KB Output is correct
151 Correct 192 ms 312988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 311060 KB Output is correct
2 Correct 143 ms 310968 KB Output is correct
3 Correct 127 ms 310988 KB Output is correct
4 Correct 134 ms 310976 KB Output is correct
5 Correct 117 ms 311032 KB Output is correct
6 Correct 125 ms 311024 KB Output is correct
7 Correct 153 ms 311012 KB Output is correct
8 Correct 127 ms 310984 KB Output is correct
9 Correct 124 ms 311008 KB Output is correct
10 Correct 125 ms 310988 KB Output is correct
11 Correct 131 ms 311092 KB Output is correct
12 Correct 137 ms 311056 KB Output is correct
13 Correct 134 ms 310968 KB Output is correct
14 Correct 118 ms 310988 KB Output is correct
15 Correct 133 ms 311056 KB Output is correct
16 Correct 125 ms 311116 KB Output is correct
17 Correct 125 ms 311168 KB Output is correct
18 Correct 131 ms 311064 KB Output is correct
19 Correct 160 ms 311072 KB Output is correct
20 Correct 141 ms 311048 KB Output is correct
21 Correct 135 ms 311104 KB Output is correct
22 Correct 132 ms 311040 KB Output is correct
23 Correct 128 ms 310988 KB Output is correct
24 Correct 126 ms 312448 KB Output is correct
25 Correct 129 ms 312472 KB Output is correct
26 Correct 135 ms 312376 KB Output is correct
27 Correct 133 ms 311896 KB Output is correct
28 Correct 132 ms 311876 KB Output is correct
29 Correct 130 ms 311972 KB Output is correct
30 Correct 146 ms 312004 KB Output is correct
31 Correct 128 ms 311908 KB Output is correct
32 Correct 137 ms 312076 KB Output is correct
33 Correct 132 ms 312920 KB Output is correct
34 Correct 144 ms 313052 KB Output is correct
35 Correct 145 ms 312992 KB Output is correct
36 Correct 186 ms 312980 KB Output is correct
37 Correct 143 ms 312920 KB Output is correct
38 Correct 151 ms 312984 KB Output is correct
39 Correct 147 ms 313988 KB Output is correct
40 Correct 156 ms 314032 KB Output is correct
41 Correct 143 ms 313952 KB Output is correct
42 Runtime error 492 ms 524288 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -