Submission #733219

# Submission time Handle Problem Language Result Execution time Memory
733219 2023-04-30T09:19:08 Z bin9638 Painting Walls (APIO20_paint) C++17
28 / 100
860 ms 524288 KB
#include <bits/stdc++.h>

#ifndef SKY
#include "paint.h"
#endif // SKY

using namespace std;

#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back

unordered_map<int,int16_t>mp[N];
int n,m,k,color[N],dp[N];
vector<int16_t>lis[N];

int minimumInstructions(int NNN, int MMM, int KKK, vector<int> CCC,vector<int> AAA, vector<vector<int>> BBB)
{
    n=NNN;
    m=MMM;
    k=KKK;
    for(int i=0;i<n;i++)
        color[i]=CCC[i];
    for(int i=0;i<m;i++)
        for(auto u:BBB[i])
            lis[u].pb(i);
    if(m==1)
    {
        for(int i=0;i<n;i++)
            if(lis[color[i]].empty())
                return -1;
        return n;
    }
    for(int i=n-1;i>=0;i--)
    {
        for(auto u:lis[color[i]])
            if(mp[i+1].find((u+1)%m)!=mp[i+1].end())
                mp[i][u]=min(m,mp[i+1][(u+1)%m]+1);
                    else mp[i][u]=1;
        for(auto u:lis[color[i]])
            if(mp[i][u]==m)
                dp[i]=1;
    }
    if(dp[0]==0)
        return -1;
    int vt=0,res=0,x=0;
    while(vt<n)
    {
        if(x+m-1<vt)
            return -1;
        int new_vt=x+m;
        for(int i=vt+1;i<=new_vt;i++)
            if(dp[i]==1)
                x=max(x,i);
        vt=new_vt;
        res++;
    }
    return res;
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,k;
    cin>>n>>m>>k;
    vector<int>C(n);
    for(int i=0;i<n;i++)
        cin>>C[i];
    vector<int>A(m);
    vector<vector<int>>B(m);
    for(int i=0;i<m;i++)
    {
        cin>>A[i];
        B[i].resize(A[i]);
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<A[i];j++)
            cin>>B[i][j];
    }
    cout<<minimumInstructions(n,m,k,C,A,B);
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 10 ms 15964 KB Output is correct
5 Correct 12 ms 15976 KB Output is correct
6 Correct 9 ms 15900 KB Output is correct
7 Correct 9 ms 15908 KB Output is correct
8 Correct 12 ms 15956 KB Output is correct
9 Correct 11 ms 15956 KB Output is correct
10 Correct 10 ms 15964 KB Output is correct
11 Correct 10 ms 16084 KB Output is correct
12 Correct 10 ms 15968 KB Output is correct
13 Correct 9 ms 16084 KB Output is correct
14 Correct 9 ms 15968 KB Output is correct
15 Correct 10 ms 16084 KB Output is correct
16 Correct 9 ms 16084 KB Output is correct
17 Correct 9 ms 16084 KB Output is correct
18 Correct 10 ms 16076 KB Output is correct
19 Correct 9 ms 15988 KB Output is correct
20 Correct 10 ms 15980 KB Output is correct
21 Correct 11 ms 15980 KB Output is correct
22 Correct 25 ms 20556 KB Output is correct
23 Correct 29 ms 20536 KB Output is correct
24 Correct 27 ms 20516 KB Output is correct
25 Correct 10 ms 16340 KB Output is correct
26 Correct 13 ms 16240 KB Output is correct
27 Correct 19 ms 19016 KB Output is correct
28 Correct 17 ms 19028 KB Output is correct
29 Correct 15 ms 19028 KB Output is correct
30 Correct 15 ms 19016 KB Output is correct
31 Correct 20 ms 20132 KB Output is correct
32 Correct 19 ms 20244 KB Output is correct
33 Correct 19 ms 20200 KB Output is correct
34 Correct 19 ms 20236 KB Output is correct
35 Correct 19 ms 20248 KB Output is correct
36 Correct 20 ms 20196 KB Output is correct
37 Correct 40 ms 23708 KB Output is correct
38 Correct 37 ms 23756 KB Output is correct
39 Correct 37 ms 23668 KB Output is correct
40 Correct 15 ms 17108 KB Output is correct
41 Correct 14 ms 16724 KB Output is correct
42 Correct 35 ms 31572 KB Output is correct
43 Correct 30 ms 26308 KB Output is correct
44 Correct 26 ms 25340 KB Output is correct
45 Correct 32 ms 31564 KB Output is correct
46 Incorrect 60 ms 38620 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 10 ms 15964 KB Output is correct
5 Correct 12 ms 15976 KB Output is correct
6 Correct 9 ms 15900 KB Output is correct
7 Correct 9 ms 15908 KB Output is correct
8 Correct 12 ms 15956 KB Output is correct
9 Correct 11 ms 15956 KB Output is correct
10 Correct 10 ms 15964 KB Output is correct
11 Correct 10 ms 16084 KB Output is correct
12 Correct 10 ms 15968 KB Output is correct
13 Correct 9 ms 16084 KB Output is correct
14 Correct 9 ms 15968 KB Output is correct
15 Correct 10 ms 16084 KB Output is correct
16 Correct 9 ms 16084 KB Output is correct
17 Correct 9 ms 16084 KB Output is correct
18 Correct 10 ms 16076 KB Output is correct
19 Correct 9 ms 15988 KB Output is correct
20 Correct 10 ms 15980 KB Output is correct
21 Correct 11 ms 15980 KB Output is correct
22 Correct 9 ms 15872 KB Output is correct
23 Correct 10 ms 15964 KB Output is correct
24 Correct 9 ms 15952 KB Output is correct
25 Correct 9 ms 15956 KB Output is correct
26 Correct 10 ms 15968 KB Output is correct
27 Correct 9 ms 15956 KB Output is correct
28 Correct 12 ms 16220 KB Output is correct
29 Correct 12 ms 16140 KB Output is correct
30 Correct 10 ms 16084 KB Output is correct
31 Correct 11 ms 16032 KB Output is correct
32 Correct 9 ms 16136 KB Output is correct
33 Correct 10 ms 15956 KB Output is correct
34 Correct 10 ms 15956 KB Output is correct
35 Correct 10 ms 15956 KB Output is correct
36 Correct 11 ms 15956 KB Output is correct
37 Correct 10 ms 16052 KB Output is correct
38 Correct 10 ms 15956 KB Output is correct
39 Correct 10 ms 15964 KB Output is correct
40 Correct 7 ms 16084 KB Output is correct
41 Correct 9 ms 15952 KB Output is correct
42 Correct 10 ms 15956 KB Output is correct
43 Correct 9 ms 15956 KB Output is correct
44 Correct 10 ms 15956 KB Output is correct
45 Correct 10 ms 16596 KB Output is correct
46 Correct 10 ms 16340 KB Output is correct
47 Correct 11 ms 16284 KB Output is correct
48 Correct 11 ms 16212 KB Output is correct
49 Correct 10 ms 16280 KB Output is correct
50 Correct 10 ms 15976 KB Output is correct
51 Correct 10 ms 16084 KB Output is correct
52 Correct 10 ms 15972 KB Output is correct
53 Correct 9 ms 16084 KB Output is correct
54 Correct 9 ms 15972 KB Output is correct
55 Correct 9 ms 16084 KB Output is correct
56 Correct 10 ms 16100 KB Output is correct
57 Correct 9 ms 16084 KB Output is correct
58 Correct 9 ms 15956 KB Output is correct
59 Correct 11 ms 16108 KB Output is correct
60 Correct 9 ms 15956 KB Output is correct
61 Correct 11 ms 16104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15872 KB Output is correct
2 Correct 10 ms 15964 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 10 ms 15964 KB Output is correct
7 Correct 12 ms 15976 KB Output is correct
8 Correct 9 ms 15900 KB Output is correct
9 Correct 9 ms 15908 KB Output is correct
10 Correct 12 ms 15956 KB Output is correct
11 Correct 11 ms 15956 KB Output is correct
12 Correct 10 ms 15964 KB Output is correct
13 Correct 10 ms 16084 KB Output is correct
14 Correct 10 ms 15968 KB Output is correct
15 Correct 9 ms 16084 KB Output is correct
16 Correct 9 ms 15968 KB Output is correct
17 Correct 10 ms 16084 KB Output is correct
18 Correct 9 ms 16084 KB Output is correct
19 Correct 9 ms 16084 KB Output is correct
20 Correct 10 ms 16076 KB Output is correct
21 Correct 9 ms 15988 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 11 ms 15980 KB Output is correct
24 Correct 25 ms 20556 KB Output is correct
25 Correct 29 ms 20536 KB Output is correct
26 Correct 27 ms 20516 KB Output is correct
27 Correct 9 ms 15952 KB Output is correct
28 Correct 9 ms 15956 KB Output is correct
29 Correct 10 ms 15968 KB Output is correct
30 Correct 9 ms 15956 KB Output is correct
31 Correct 12 ms 16220 KB Output is correct
32 Correct 12 ms 16140 KB Output is correct
33 Correct 10 ms 16084 KB Output is correct
34 Correct 11 ms 16032 KB Output is correct
35 Correct 9 ms 16136 KB Output is correct
36 Correct 10 ms 15956 KB Output is correct
37 Correct 10 ms 15956 KB Output is correct
38 Correct 10 ms 15956 KB Output is correct
39 Correct 11 ms 15956 KB Output is correct
40 Correct 10 ms 16052 KB Output is correct
41 Correct 10 ms 15956 KB Output is correct
42 Correct 10 ms 15964 KB Output is correct
43 Correct 7 ms 16084 KB Output is correct
44 Correct 9 ms 15952 KB Output is correct
45 Correct 10 ms 15956 KB Output is correct
46 Correct 9 ms 15956 KB Output is correct
47 Correct 10 ms 15956 KB Output is correct
48 Correct 10 ms 16596 KB Output is correct
49 Correct 10 ms 16340 KB Output is correct
50 Correct 11 ms 16284 KB Output is correct
51 Correct 11 ms 16212 KB Output is correct
52 Correct 10 ms 16280 KB Output is correct
53 Correct 10 ms 15976 KB Output is correct
54 Correct 10 ms 16084 KB Output is correct
55 Correct 10 ms 15972 KB Output is correct
56 Correct 9 ms 16084 KB Output is correct
57 Correct 9 ms 15972 KB Output is correct
58 Correct 9 ms 16084 KB Output is correct
59 Correct 10 ms 16100 KB Output is correct
60 Correct 9 ms 16084 KB Output is correct
61 Correct 9 ms 15956 KB Output is correct
62 Correct 11 ms 16108 KB Output is correct
63 Correct 9 ms 15956 KB Output is correct
64 Correct 11 ms 16104 KB Output is correct
65 Correct 14 ms 17876 KB Output is correct
66 Correct 11 ms 16792 KB Output is correct
67 Correct 14 ms 18388 KB Output is correct
68 Correct 14 ms 17504 KB Output is correct
69 Correct 15 ms 18004 KB Output is correct
70 Correct 15 ms 16516 KB Output is correct
71 Correct 12 ms 16620 KB Output is correct
72 Correct 11 ms 16596 KB Output is correct
73 Correct 11 ms 16340 KB Output is correct
74 Correct 12 ms 16596 KB Output is correct
75 Correct 11 ms 16468 KB Output is correct
76 Correct 31 ms 19240 KB Output is correct
77 Correct 25 ms 19796 KB Output is correct
78 Correct 29 ms 20256 KB Output is correct
79 Correct 18 ms 20052 KB Output is correct
80 Correct 18 ms 20148 KB Output is correct
81 Correct 18 ms 20060 KB Output is correct
82 Correct 22 ms 20064 KB Output is correct
83 Correct 18 ms 20152 KB Output is correct
84 Correct 16 ms 16724 KB Output is correct
85 Correct 16 ms 16724 KB Output is correct
86 Correct 13 ms 16724 KB Output is correct
87 Correct 15 ms 16724 KB Output is correct
88 Correct 13 ms 16724 KB Output is correct
89 Correct 12 ms 16724 KB Output is correct
90 Correct 35 ms 20564 KB Output is correct
91 Correct 33 ms 20600 KB Output is correct
92 Correct 38 ms 20648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15872 KB Output is correct
2 Correct 10 ms 15964 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 10 ms 15964 KB Output is correct
7 Correct 12 ms 15976 KB Output is correct
8 Correct 9 ms 15900 KB Output is correct
9 Correct 9 ms 15908 KB Output is correct
10 Correct 12 ms 15956 KB Output is correct
11 Correct 11 ms 15956 KB Output is correct
12 Correct 10 ms 15964 KB Output is correct
13 Correct 10 ms 16084 KB Output is correct
14 Correct 10 ms 15968 KB Output is correct
15 Correct 9 ms 16084 KB Output is correct
16 Correct 9 ms 15968 KB Output is correct
17 Correct 10 ms 16084 KB Output is correct
18 Correct 9 ms 16084 KB Output is correct
19 Correct 9 ms 16084 KB Output is correct
20 Correct 10 ms 16076 KB Output is correct
21 Correct 9 ms 15988 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 11 ms 15980 KB Output is correct
24 Correct 25 ms 20556 KB Output is correct
25 Correct 29 ms 20536 KB Output is correct
26 Correct 27 ms 20516 KB Output is correct
27 Correct 10 ms 16340 KB Output is correct
28 Correct 13 ms 16240 KB Output is correct
29 Correct 19 ms 19016 KB Output is correct
30 Correct 17 ms 19028 KB Output is correct
31 Correct 15 ms 19028 KB Output is correct
32 Correct 15 ms 19016 KB Output is correct
33 Correct 20 ms 20132 KB Output is correct
34 Correct 19 ms 20244 KB Output is correct
35 Correct 19 ms 20200 KB Output is correct
36 Correct 19 ms 20236 KB Output is correct
37 Correct 19 ms 20248 KB Output is correct
38 Correct 20 ms 20196 KB Output is correct
39 Correct 40 ms 23708 KB Output is correct
40 Correct 37 ms 23756 KB Output is correct
41 Correct 37 ms 23668 KB Output is correct
42 Correct 9 ms 15952 KB Output is correct
43 Correct 9 ms 15956 KB Output is correct
44 Correct 10 ms 15968 KB Output is correct
45 Correct 9 ms 15956 KB Output is correct
46 Correct 12 ms 16220 KB Output is correct
47 Correct 12 ms 16140 KB Output is correct
48 Correct 10 ms 16084 KB Output is correct
49 Correct 11 ms 16032 KB Output is correct
50 Correct 9 ms 16136 KB Output is correct
51 Correct 10 ms 15956 KB Output is correct
52 Correct 10 ms 15956 KB Output is correct
53 Correct 10 ms 15956 KB Output is correct
54 Correct 11 ms 15956 KB Output is correct
55 Correct 10 ms 16052 KB Output is correct
56 Correct 10 ms 15956 KB Output is correct
57 Correct 10 ms 15964 KB Output is correct
58 Correct 7 ms 16084 KB Output is correct
59 Correct 9 ms 15952 KB Output is correct
60 Correct 10 ms 15956 KB Output is correct
61 Correct 9 ms 15956 KB Output is correct
62 Correct 10 ms 15956 KB Output is correct
63 Correct 10 ms 16596 KB Output is correct
64 Correct 10 ms 16340 KB Output is correct
65 Correct 11 ms 16284 KB Output is correct
66 Correct 11 ms 16212 KB Output is correct
67 Correct 10 ms 16280 KB Output is correct
68 Correct 10 ms 15976 KB Output is correct
69 Correct 10 ms 16084 KB Output is correct
70 Correct 10 ms 15972 KB Output is correct
71 Correct 9 ms 16084 KB Output is correct
72 Correct 9 ms 15972 KB Output is correct
73 Correct 9 ms 16084 KB Output is correct
74 Correct 10 ms 16100 KB Output is correct
75 Correct 9 ms 16084 KB Output is correct
76 Correct 9 ms 15956 KB Output is correct
77 Correct 11 ms 16108 KB Output is correct
78 Correct 9 ms 15956 KB Output is correct
79 Correct 11 ms 16104 KB Output is correct
80 Correct 14 ms 17876 KB Output is correct
81 Correct 11 ms 16792 KB Output is correct
82 Correct 14 ms 18388 KB Output is correct
83 Correct 14 ms 17504 KB Output is correct
84 Correct 15 ms 18004 KB Output is correct
85 Correct 15 ms 16516 KB Output is correct
86 Correct 12 ms 16620 KB Output is correct
87 Correct 11 ms 16596 KB Output is correct
88 Correct 11 ms 16340 KB Output is correct
89 Correct 12 ms 16596 KB Output is correct
90 Correct 11 ms 16468 KB Output is correct
91 Correct 31 ms 19240 KB Output is correct
92 Correct 25 ms 19796 KB Output is correct
93 Correct 29 ms 20256 KB Output is correct
94 Correct 18 ms 20052 KB Output is correct
95 Correct 18 ms 20148 KB Output is correct
96 Correct 18 ms 20060 KB Output is correct
97 Correct 22 ms 20064 KB Output is correct
98 Correct 18 ms 20152 KB Output is correct
99 Correct 16 ms 16724 KB Output is correct
100 Correct 16 ms 16724 KB Output is correct
101 Correct 13 ms 16724 KB Output is correct
102 Correct 15 ms 16724 KB Output is correct
103 Correct 13 ms 16724 KB Output is correct
104 Correct 12 ms 16724 KB Output is correct
105 Correct 35 ms 20564 KB Output is correct
106 Correct 33 ms 20600 KB Output is correct
107 Correct 38 ms 20648 KB Output is correct
108 Correct 17 ms 19668 KB Output is correct
109 Correct 849 ms 423436 KB Output is correct
110 Correct 516 ms 220392 KB Output is correct
111 Correct 405 ms 177704 KB Output is correct
112 Correct 613 ms 211156 KB Output is correct
113 Correct 339 ms 132732 KB Output is correct
114 Correct 24 ms 20336 KB Output is correct
115 Correct 26 ms 20280 KB Output is correct
116 Correct 30 ms 22116 KB Output is correct
117 Correct 25 ms 20148 KB Output is correct
118 Correct 26 ms 20844 KB Output is correct
119 Correct 22 ms 20260 KB Output is correct
120 Correct 31 ms 20484 KB Output is correct
121 Correct 18 ms 18884 KB Output is correct
122 Correct 31 ms 20820 KB Output is correct
123 Correct 15 ms 18536 KB Output is correct
124 Correct 35 ms 22092 KB Output is correct
125 Correct 18 ms 20180 KB Output is correct
126 Correct 17 ms 19464 KB Output is correct
127 Correct 22 ms 20308 KB Output is correct
128 Correct 16 ms 19028 KB Output is correct
129 Correct 17 ms 19156 KB Output is correct
130 Correct 15 ms 19668 KB Output is correct
131 Runtime error 860 ms 524288 KB Execution killed with signal 9
132 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15872 KB Output is correct
2 Correct 10 ms 15964 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 10 ms 15964 KB Output is correct
7 Correct 12 ms 15976 KB Output is correct
8 Correct 9 ms 15900 KB Output is correct
9 Correct 9 ms 15908 KB Output is correct
10 Correct 12 ms 15956 KB Output is correct
11 Correct 11 ms 15956 KB Output is correct
12 Correct 10 ms 15964 KB Output is correct
13 Correct 10 ms 16084 KB Output is correct
14 Correct 10 ms 15968 KB Output is correct
15 Correct 9 ms 16084 KB Output is correct
16 Correct 9 ms 15968 KB Output is correct
17 Correct 10 ms 16084 KB Output is correct
18 Correct 9 ms 16084 KB Output is correct
19 Correct 9 ms 16084 KB Output is correct
20 Correct 10 ms 16076 KB Output is correct
21 Correct 9 ms 15988 KB Output is correct
22 Correct 10 ms 15980 KB Output is correct
23 Correct 11 ms 15980 KB Output is correct
24 Correct 25 ms 20556 KB Output is correct
25 Correct 29 ms 20536 KB Output is correct
26 Correct 27 ms 20516 KB Output is correct
27 Correct 10 ms 16340 KB Output is correct
28 Correct 13 ms 16240 KB Output is correct
29 Correct 19 ms 19016 KB Output is correct
30 Correct 17 ms 19028 KB Output is correct
31 Correct 15 ms 19028 KB Output is correct
32 Correct 15 ms 19016 KB Output is correct
33 Correct 20 ms 20132 KB Output is correct
34 Correct 19 ms 20244 KB Output is correct
35 Correct 19 ms 20200 KB Output is correct
36 Correct 19 ms 20236 KB Output is correct
37 Correct 19 ms 20248 KB Output is correct
38 Correct 20 ms 20196 KB Output is correct
39 Correct 40 ms 23708 KB Output is correct
40 Correct 37 ms 23756 KB Output is correct
41 Correct 37 ms 23668 KB Output is correct
42 Correct 15 ms 17108 KB Output is correct
43 Correct 14 ms 16724 KB Output is correct
44 Correct 35 ms 31572 KB Output is correct
45 Correct 30 ms 26308 KB Output is correct
46 Correct 26 ms 25340 KB Output is correct
47 Correct 32 ms 31564 KB Output is correct
48 Incorrect 60 ms 38620 KB Output isn't correct
49 Halted 0 ms 0 KB -