Submission #934300

# Submission time Handle Problem Language Result Execution time Memory
934300 2024-02-27T06:38:23 Z irmuun Painting Walls (APIO20_paint) C++17
51 / 100
265 ms 524288 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
 
int minimumInstructions(int n,int m,int k,vector<int>C,vector<int>A,vector<vector<int>>B){
    vector<vector<int>>q(n,vector<int>(m));
    vector<vector<bool>>have(k,vector<bool>(m,0));
    vector<int>cnt(k,0);
    int mx=0;
    for(int i=0;i<m;i++){
        for(auto x:B[i]){
            have[x][i]=true;
            cnt[x]++;
            mx=max(mx,cnt[x]);
        }
    }
    if(mx<=1){
        vector<int>can(k,-1);
        for(int i=0;i<m;i++){
            for(int j=0;j<A[i];j++){
                can[B[i][j]]=i;
            }
        }
        for(int i=0;i<n;i++){
            if(can[C[i]]==-1) return -1;
        }
        vector<int>count(n,0);
        int cur=1;
        count[n-1]=1;
        for(int i=n-2;i>=0;i--){
            if(can[C[i]]==can[C[i+1]]-1||(can[C[i+1]]==0&&can[C[i]]==m-1)){
                cur++;
            }
            else{
                cur=1;
            }
            count[i]=cur;
        }
        int ans=0;
        bool ok=true;
        if(count[0]<m) return -1;
        ans++;
        int r=m-1,nxt=0;
        for(int i=1;i<n;i++){
            if(count[i]>=m){
                nxt=i;
            }
            if(i>r){
                r=nxt+m-1;
                if(i>r) return -1;
                ans++;
            }
        }
        return ans;
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<m;j++){
            if(have[C[i]][j]==false){
                q[i][j]=-1e9;
            }
            else if(i==n-1||have[C[i+1]][(j+1)%m]==false){
                q[i][j]=1;
            }
            else{
                q[i][j]=q[i+1][(j+1)%m]+1;
            }
        }
    }
    vector<int>mn(n+1,1e9);
    mn[n]=0;
    multiset<int>st;
    for(int i=n-m+1;i<=n;i++){
        st.insert(mn[i]);
    }
    for(int i=n-m;i>=0;i--){
        bool ok=false;
        for(int j=0;j<m;j++){
            if(q[i][j]>=m){
                ok=true;
                break;
            }
        }
        if(ok){
            mn[i]=*st.begin()+1;
        }
        st.erase(st.find(mn[i+m]));
        st.insert(mn[i]);
    }
    if(mn[0]>=1e9) return -1;
    return mn[0];
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:47:14: warning: unused variable 'ok' [-Wunused-variable]
   47 |         bool ok=true;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 10128 KB Output is correct
14 Correct 7 ms 10076 KB Output is correct
15 Correct 7 ms 10328 KB Output is correct
16 Correct 8 ms 10076 KB Output is correct
17 Correct 8 ms 10180 KB Output is correct
18 Correct 8 ms 10076 KB Output is correct
19 Correct 7 ms 10076 KB Output is correct
20 Correct 7 ms 10036 KB Output is correct
21 Correct 8 ms 10076 KB Output is correct
22 Correct 16 ms 11352 KB Output is correct
23 Correct 15 ms 11608 KB Output is correct
24 Correct 23 ms 11460 KB Output is correct
25 Correct 3 ms 1624 KB Output is correct
26 Correct 3 ms 1624 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 3 ms 1628 KB Output is correct
29 Correct 3 ms 1824 KB Output is correct
30 Correct 3 ms 1576 KB Output is correct
31 Correct 81 ms 189624 KB Output is correct
32 Correct 86 ms 189776 KB Output is correct
33 Correct 80 ms 189744 KB Output is correct
34 Correct 76 ms 189632 KB Output is correct
35 Correct 82 ms 189840 KB Output is correct
36 Correct 77 ms 190032 KB Output is correct
37 Correct 86 ms 190544 KB Output is correct
38 Correct 87 ms 190544 KB Output is correct
39 Correct 84 ms 190520 KB Output is correct
40 Correct 11 ms 6492 KB Output is correct
41 Correct 7 ms 4188 KB Output is correct
42 Correct 12 ms 6996 KB Output is correct
43 Correct 8 ms 4700 KB Output is correct
44 Correct 7 ms 4444 KB Output is correct
45 Correct 12 ms 7176 KB Output is correct
46 Runtime error 265 ms 524288 KB Execution killed with signal 9
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 10128 KB Output is correct
14 Correct 7 ms 10076 KB Output is correct
15 Correct 7 ms 10328 KB Output is correct
16 Correct 8 ms 10076 KB Output is correct
17 Correct 8 ms 10180 KB Output is correct
18 Correct 8 ms 10076 KB Output is correct
19 Correct 7 ms 10076 KB Output is correct
20 Correct 7 ms 10036 KB Output is correct
21 Correct 8 ms 10076 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 8 ms 7044 KB Output is correct
34 Correct 7 ms 5468 KB Output is correct
35 Correct 5 ms 4700 KB Output is correct
36 Correct 9 ms 7772 KB Output is correct
37 Correct 11 ms 6488 KB Output is correct
38 Correct 6 ms 6748 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 6064 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 10 ms 7516 KB Output is correct
43 Correct 10 ms 7260 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 8 ms 9820 KB Output is correct
51 Correct 8 ms 9820 KB Output is correct
52 Correct 8 ms 9816 KB Output is correct
53 Correct 8 ms 9820 KB Output is correct
54 Correct 8 ms 9820 KB Output is correct
55 Correct 9 ms 9820 KB Output is correct
56 Correct 9 ms 9820 KB Output is correct
57 Correct 1 ms 856 KB Output is correct
58 Correct 8 ms 9820 KB Output is correct
59 Correct 1 ms 860 KB Output is correct
60 Correct 8 ms 9744 KB Output is correct
61 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 10128 KB Output is correct
16 Correct 7 ms 10076 KB Output is correct
17 Correct 7 ms 10328 KB Output is correct
18 Correct 8 ms 10076 KB Output is correct
19 Correct 8 ms 10180 KB Output is correct
20 Correct 8 ms 10076 KB Output is correct
21 Correct 7 ms 10076 KB Output is correct
22 Correct 7 ms 10036 KB Output is correct
23 Correct 8 ms 10076 KB Output is correct
24 Correct 16 ms 11352 KB Output is correct
25 Correct 15 ms 11608 KB Output is correct
26 Correct 23 ms 11460 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 7044 KB Output is correct
37 Correct 7 ms 5468 KB Output is correct
38 Correct 5 ms 4700 KB Output is correct
39 Correct 9 ms 7772 KB Output is correct
40 Correct 11 ms 6488 KB Output is correct
41 Correct 6 ms 6748 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 8 ms 6064 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 10 ms 7516 KB Output is correct
46 Correct 10 ms 7260 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 8 ms 9820 KB Output is correct
54 Correct 8 ms 9820 KB Output is correct
55 Correct 8 ms 9816 KB Output is correct
56 Correct 8 ms 9820 KB Output is correct
57 Correct 8 ms 9820 KB Output is correct
58 Correct 9 ms 9820 KB Output is correct
59 Correct 9 ms 9820 KB Output is correct
60 Correct 1 ms 856 KB Output is correct
61 Correct 8 ms 9820 KB Output is correct
62 Correct 1 ms 860 KB Output is correct
63 Correct 8 ms 9744 KB Output is correct
64 Correct 1 ms 860 KB Output is correct
65 Correct 1 ms 644 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 1 ms 856 KB Output is correct
70 Correct 11 ms 7004 KB Output is correct
71 Correct 8 ms 5980 KB Output is correct
72 Correct 6 ms 4956 KB Output is correct
73 Correct 6 ms 5724 KB Output is correct
74 Correct 9 ms 6492 KB Output is correct
75 Correct 13 ms 8024 KB Output is correct
76 Correct 17 ms 6492 KB Output is correct
77 Correct 14 ms 7772 KB Output is correct
78 Correct 20 ms 8796 KB Output is correct
79 Correct 1 ms 876 KB Output is correct
80 Correct 1 ms 860 KB Output is correct
81 Correct 1 ms 860 KB Output is correct
82 Correct 1 ms 860 KB Output is correct
83 Correct 1 ms 860 KB Output is correct
84 Correct 9 ms 9820 KB Output is correct
85 Correct 10 ms 9820 KB Output is correct
86 Correct 9 ms 9820 KB Output is correct
87 Correct 9 ms 9820 KB Output is correct
88 Correct 9 ms 9820 KB Output is correct
89 Correct 10 ms 9924 KB Output is correct
90 Correct 20 ms 11100 KB Output is correct
91 Correct 20 ms 11100 KB Output is correct
92 Correct 20 ms 10980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 10128 KB Output is correct
16 Correct 7 ms 10076 KB Output is correct
17 Correct 7 ms 10328 KB Output is correct
18 Correct 8 ms 10076 KB Output is correct
19 Correct 8 ms 10180 KB Output is correct
20 Correct 8 ms 10076 KB Output is correct
21 Correct 7 ms 10076 KB Output is correct
22 Correct 7 ms 10036 KB Output is correct
23 Correct 8 ms 10076 KB Output is correct
24 Correct 16 ms 11352 KB Output is correct
25 Correct 15 ms 11608 KB Output is correct
26 Correct 23 ms 11460 KB Output is correct
27 Correct 3 ms 1624 KB Output is correct
28 Correct 3 ms 1624 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 3 ms 1628 KB Output is correct
31 Correct 3 ms 1824 KB Output is correct
32 Correct 3 ms 1576 KB Output is correct
33 Correct 81 ms 189624 KB Output is correct
34 Correct 86 ms 189776 KB Output is correct
35 Correct 80 ms 189744 KB Output is correct
36 Correct 76 ms 189632 KB Output is correct
37 Correct 82 ms 189840 KB Output is correct
38 Correct 77 ms 190032 KB Output is correct
39 Correct 86 ms 190544 KB Output is correct
40 Correct 87 ms 190544 KB Output is correct
41 Correct 84 ms 190520 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 600 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 8 ms 7044 KB Output is correct
52 Correct 7 ms 5468 KB Output is correct
53 Correct 5 ms 4700 KB Output is correct
54 Correct 9 ms 7772 KB Output is correct
55 Correct 11 ms 6488 KB Output is correct
56 Correct 6 ms 6748 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 8 ms 6064 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 10 ms 7516 KB Output is correct
61 Correct 10 ms 7260 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 8 ms 9820 KB Output is correct
69 Correct 8 ms 9820 KB Output is correct
70 Correct 8 ms 9816 KB Output is correct
71 Correct 8 ms 9820 KB Output is correct
72 Correct 8 ms 9820 KB Output is correct
73 Correct 9 ms 9820 KB Output is correct
74 Correct 9 ms 9820 KB Output is correct
75 Correct 1 ms 856 KB Output is correct
76 Correct 8 ms 9820 KB Output is correct
77 Correct 1 ms 860 KB Output is correct
78 Correct 8 ms 9744 KB Output is correct
79 Correct 1 ms 860 KB Output is correct
80 Correct 1 ms 644 KB Output is correct
81 Correct 1 ms 348 KB Output is correct
82 Correct 1 ms 604 KB Output is correct
83 Correct 1 ms 604 KB Output is correct
84 Correct 1 ms 856 KB Output is correct
85 Correct 11 ms 7004 KB Output is correct
86 Correct 8 ms 5980 KB Output is correct
87 Correct 6 ms 4956 KB Output is correct
88 Correct 6 ms 5724 KB Output is correct
89 Correct 9 ms 6492 KB Output is correct
90 Correct 13 ms 8024 KB Output is correct
91 Correct 17 ms 6492 KB Output is correct
92 Correct 14 ms 7772 KB Output is correct
93 Correct 20 ms 8796 KB Output is correct
94 Correct 1 ms 876 KB Output is correct
95 Correct 1 ms 860 KB Output is correct
96 Correct 1 ms 860 KB Output is correct
97 Correct 1 ms 860 KB Output is correct
98 Correct 1 ms 860 KB Output is correct
99 Correct 9 ms 9820 KB Output is correct
100 Correct 10 ms 9820 KB Output is correct
101 Correct 9 ms 9820 KB Output is correct
102 Correct 9 ms 9820 KB Output is correct
103 Correct 9 ms 9820 KB Output is correct
104 Correct 10 ms 9924 KB Output is correct
105 Correct 20 ms 11100 KB Output is correct
106 Correct 20 ms 11100 KB Output is correct
107 Correct 20 ms 10980 KB Output is correct
108 Correct 3 ms 1628 KB Output is correct
109 Correct 56 ms 36164 KB Output is correct
110 Correct 46 ms 32076 KB Output is correct
111 Correct 40 ms 31528 KB Output is correct
112 Correct 56 ms 45140 KB Output is correct
113 Correct 62 ms 41056 KB Output is correct
114 Correct 57 ms 62724 KB Output is correct
115 Correct 16 ms 10584 KB Output is correct
116 Correct 69 ms 67924 KB Output is correct
117 Correct 50 ms 40492 KB Output is correct
118 Correct 20 ms 12636 KB Output is correct
119 Correct 86 ms 109268 KB Output is correct
120 Correct 91 ms 111184 KB Output is correct
121 Correct 74 ms 95524 KB Output is correct
122 Correct 44 ms 34104 KB Output is correct
123 Correct 26 ms 27740 KB Output is correct
124 Correct 34 ms 19692 KB Output is correct
125 Correct 18 ms 14172 KB Output is correct
126 Correct 10 ms 6488 KB Output is correct
127 Correct 54 ms 50084 KB Output is correct
128 Correct 15 ms 13912 KB Output is correct
129 Correct 18 ms 15708 KB Output is correct
130 Correct 3 ms 1628 KB Output is correct
131 Correct 78 ms 50776 KB Output is correct
132 Correct 95 ms 64292 KB Output is correct
133 Correct 84 ms 72292 KB Output is correct
134 Correct 110 ms 78928 KB Output is correct
135 Correct 152 ms 84784 KB Output is correct
136 Correct 143 ms 189748 KB Output is correct
137 Correct 144 ms 189780 KB Output is correct
138 Correct 163 ms 189640 KB Output is correct
139 Correct 144 ms 189780 KB Output is correct
140 Correct 141 ms 189776 KB Output is correct
141 Correct 147 ms 189760 KB Output is correct
142 Correct 156 ms 190292 KB Output is correct
143 Correct 135 ms 164404 KB Output is correct
144 Correct 156 ms 190288 KB Output is correct
145 Correct 142 ms 164400 KB Output is correct
146 Correct 161 ms 190292 KB Output is correct
147 Correct 124 ms 164404 KB Output is correct
148 Correct 159 ms 189524 KB Output is correct
149 Correct 88 ms 98372 KB Output is correct
150 Correct 68 ms 67408 KB Output is correct
151 Correct 59 ms 52816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 10128 KB Output is correct
16 Correct 7 ms 10076 KB Output is correct
17 Correct 7 ms 10328 KB Output is correct
18 Correct 8 ms 10076 KB Output is correct
19 Correct 8 ms 10180 KB Output is correct
20 Correct 8 ms 10076 KB Output is correct
21 Correct 7 ms 10076 KB Output is correct
22 Correct 7 ms 10036 KB Output is correct
23 Correct 8 ms 10076 KB Output is correct
24 Correct 16 ms 11352 KB Output is correct
25 Correct 15 ms 11608 KB Output is correct
26 Correct 23 ms 11460 KB Output is correct
27 Correct 3 ms 1624 KB Output is correct
28 Correct 3 ms 1624 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 3 ms 1628 KB Output is correct
31 Correct 3 ms 1824 KB Output is correct
32 Correct 3 ms 1576 KB Output is correct
33 Correct 81 ms 189624 KB Output is correct
34 Correct 86 ms 189776 KB Output is correct
35 Correct 80 ms 189744 KB Output is correct
36 Correct 76 ms 189632 KB Output is correct
37 Correct 82 ms 189840 KB Output is correct
38 Correct 77 ms 190032 KB Output is correct
39 Correct 86 ms 190544 KB Output is correct
40 Correct 87 ms 190544 KB Output is correct
41 Correct 84 ms 190520 KB Output is correct
42 Correct 11 ms 6492 KB Output is correct
43 Correct 7 ms 4188 KB Output is correct
44 Correct 12 ms 6996 KB Output is correct
45 Correct 8 ms 4700 KB Output is correct
46 Correct 7 ms 4444 KB Output is correct
47 Correct 12 ms 7176 KB Output is correct
48 Runtime error 265 ms 524288 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -