Submission #733222

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

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

using namespace std;

#define N 100010
#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];

int minimumInstructions(int NNN, int MMM, int KKK, vector<int> CCC,vector<int> AAA, vector<vector<int>> BBB)
{
    vector<int16_t>lis[N];
    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 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 4 ms 8020 KB Output is correct
4 Correct 5 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 5 ms 8016 KB Output is correct
7 Correct 6 ms 8020 KB Output is correct
8 Correct 5 ms 8020 KB Output is correct
9 Correct 5 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 7 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 9 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 5 ms 8148 KB Output is correct
21 Correct 5 ms 8164 KB Output is correct
22 Correct 37 ms 12068 KB Output is correct
23 Correct 22 ms 12116 KB Output is correct
24 Correct 21 ms 12116 KB Output is correct
25 Correct 5 ms 8276 KB Output is correct
26 Correct 6 ms 8276 KB Output is correct
27 Correct 14 ms 11240 KB Output is correct
28 Correct 9 ms 11208 KB Output is correct
29 Correct 10 ms 11240 KB Output is correct
30 Correct 13 ms 11240 KB Output is correct
31 Correct 16 ms 12064 KB Output is correct
32 Correct 15 ms 12176 KB Output is correct
33 Correct 16 ms 12116 KB Output is correct
34 Correct 23 ms 12076 KB Output is correct
35 Correct 16 ms 12160 KB Output is correct
36 Correct 14 ms 12116 KB Output is correct
37 Correct 29 ms 15264 KB Output is correct
38 Correct 28 ms 15144 KB Output is correct
39 Correct 35 ms 15224 KB Output is correct
40 Correct 11 ms 9096 KB Output is correct
41 Correct 9 ms 8700 KB Output is correct
42 Correct 28 ms 23444 KB Output is correct
43 Correct 21 ms 18312 KB Output is correct
44 Correct 19 ms 17428 KB Output is correct
45 Correct 33 ms 23540 KB Output is correct
46 Incorrect 61 ms 29676 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 4 ms 8020 KB Output is correct
4 Correct 5 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 5 ms 8016 KB Output is correct
7 Correct 6 ms 8020 KB Output is correct
8 Correct 5 ms 8020 KB Output is correct
9 Correct 5 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 7 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 4 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 9 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 5 ms 8148 KB Output is correct
21 Correct 5 ms 8164 KB Output is correct
22 Correct 6 ms 8020 KB Output is correct
23 Correct 7 ms 8020 KB Output is correct
24 Correct 7 ms 8020 KB Output is correct
25 Correct 5 ms 8020 KB Output is correct
26 Correct 5 ms 8104 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8404 KB Output is correct
29 Correct 7 ms 8236 KB Output is correct
30 Correct 5 ms 8276 KB Output is correct
31 Correct 6 ms 8292 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 7 ms 8148 KB Output is correct
34 Correct 6 ms 8148 KB Output is correct
35 Correct 6 ms 8148 KB Output is correct
36 Correct 5 ms 8148 KB Output is correct
37 Correct 5 ms 8148 KB Output is correct
38 Correct 5 ms 8148 KB Output is correct
39 Correct 6 ms 8196 KB Output is correct
40 Correct 6 ms 8148 KB Output is correct
41 Correct 5 ms 8148 KB Output is correct
42 Correct 5 ms 8148 KB Output is correct
43 Correct 5 ms 8148 KB Output is correct
44 Correct 5 ms 8148 KB Output is correct
45 Correct 7 ms 8764 KB Output is correct
46 Correct 6 ms 8532 KB Output is correct
47 Correct 6 ms 8532 KB Output is correct
48 Correct 7 ms 8404 KB Output is correct
49 Correct 6 ms 8340 KB Output is correct
50 Correct 6 ms 8204 KB Output is correct
51 Correct 6 ms 8148 KB Output is correct
52 Correct 5 ms 8148 KB Output is correct
53 Correct 7 ms 8148 KB Output is correct
54 Correct 4 ms 8148 KB Output is correct
55 Correct 4 ms 8224 KB Output is correct
56 Correct 5 ms 8276 KB Output is correct
57 Correct 5 ms 8148 KB Output is correct
58 Correct 6 ms 8148 KB Output is correct
59 Correct 4 ms 8148 KB Output is correct
60 Correct 5 ms 8148 KB Output is correct
61 Correct 5 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 7 ms 8020 KB Output is correct
3 Correct 6 ms 8020 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 4 ms 8020 KB Output is correct
6 Correct 5 ms 8020 KB Output is correct
7 Correct 6 ms 8020 KB Output is correct
8 Correct 5 ms 8016 KB Output is correct
9 Correct 6 ms 8020 KB Output is correct
10 Correct 5 ms 8020 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 4 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 7 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 9 ms 8148 KB Output is correct
21 Correct 5 ms 8148 KB Output is correct
22 Correct 5 ms 8148 KB Output is correct
23 Correct 5 ms 8164 KB Output is correct
24 Correct 37 ms 12068 KB Output is correct
25 Correct 22 ms 12116 KB Output is correct
26 Correct 21 ms 12116 KB Output is correct
27 Correct 7 ms 8020 KB Output is correct
28 Correct 5 ms 8020 KB Output is correct
29 Correct 5 ms 8104 KB Output is correct
30 Correct 5 ms 8148 KB Output is correct
31 Correct 6 ms 8404 KB Output is correct
32 Correct 7 ms 8236 KB Output is correct
33 Correct 5 ms 8276 KB Output is correct
34 Correct 6 ms 8292 KB Output is correct
35 Correct 6 ms 8276 KB Output is correct
36 Correct 7 ms 8148 KB Output is correct
37 Correct 6 ms 8148 KB Output is correct
38 Correct 6 ms 8148 KB Output is correct
39 Correct 5 ms 8148 KB Output is correct
40 Correct 5 ms 8148 KB Output is correct
41 Correct 5 ms 8148 KB Output is correct
42 Correct 6 ms 8196 KB Output is correct
43 Correct 6 ms 8148 KB Output is correct
44 Correct 5 ms 8148 KB Output is correct
45 Correct 5 ms 8148 KB Output is correct
46 Correct 5 ms 8148 KB Output is correct
47 Correct 5 ms 8148 KB Output is correct
48 Correct 7 ms 8764 KB Output is correct
49 Correct 6 ms 8532 KB Output is correct
50 Correct 6 ms 8532 KB Output is correct
51 Correct 7 ms 8404 KB Output is correct
52 Correct 6 ms 8340 KB Output is correct
53 Correct 6 ms 8204 KB Output is correct
54 Correct 6 ms 8148 KB Output is correct
55 Correct 5 ms 8148 KB Output is correct
56 Correct 7 ms 8148 KB Output is correct
57 Correct 4 ms 8148 KB Output is correct
58 Correct 4 ms 8224 KB Output is correct
59 Correct 5 ms 8276 KB Output is correct
60 Correct 5 ms 8148 KB Output is correct
61 Correct 6 ms 8148 KB Output is correct
62 Correct 4 ms 8148 KB Output is correct
63 Correct 5 ms 8148 KB Output is correct
64 Correct 5 ms 8148 KB Output is correct
65 Correct 9 ms 10068 KB Output is correct
66 Correct 8 ms 8916 KB Output is correct
67 Correct 11 ms 10536 KB Output is correct
68 Correct 13 ms 9684 KB Output is correct
69 Correct 13 ms 10140 KB Output is correct
70 Correct 10 ms 8660 KB Output is correct
71 Correct 11 ms 8648 KB Output is correct
72 Correct 7 ms 8660 KB Output is correct
73 Correct 7 ms 8404 KB Output is correct
74 Correct 7 ms 8660 KB Output is correct
75 Correct 7 ms 8584 KB Output is correct
76 Correct 20 ms 10812 KB Output is correct
77 Correct 21 ms 11220 KB Output is correct
78 Correct 42 ms 11596 KB Output is correct
79 Correct 18 ms 12280 KB Output is correct
80 Correct 18 ms 12244 KB Output is correct
81 Correct 14 ms 12296 KB Output is correct
82 Correct 14 ms 12208 KB Output is correct
83 Correct 14 ms 12244 KB Output is correct
84 Correct 8 ms 8788 KB Output is correct
85 Correct 8 ms 8788 KB Output is correct
86 Correct 10 ms 8916 KB Output is correct
87 Correct 8 ms 8788 KB Output is correct
88 Correct 7 ms 8788 KB Output is correct
89 Correct 7 ms 8788 KB Output is correct
90 Correct 29 ms 11852 KB Output is correct
91 Correct 33 ms 11808 KB Output is correct
92 Correct 30 ms 11808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 7 ms 8020 KB Output is correct
3 Correct 6 ms 8020 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 4 ms 8020 KB Output is correct
6 Correct 5 ms 8020 KB Output is correct
7 Correct 6 ms 8020 KB Output is correct
8 Correct 5 ms 8016 KB Output is correct
9 Correct 6 ms 8020 KB Output is correct
10 Correct 5 ms 8020 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 4 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 7 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 9 ms 8148 KB Output is correct
21 Correct 5 ms 8148 KB Output is correct
22 Correct 5 ms 8148 KB Output is correct
23 Correct 5 ms 8164 KB Output is correct
24 Correct 37 ms 12068 KB Output is correct
25 Correct 22 ms 12116 KB Output is correct
26 Correct 21 ms 12116 KB Output is correct
27 Correct 5 ms 8276 KB Output is correct
28 Correct 6 ms 8276 KB Output is correct
29 Correct 14 ms 11240 KB Output is correct
30 Correct 9 ms 11208 KB Output is correct
31 Correct 10 ms 11240 KB Output is correct
32 Correct 13 ms 11240 KB Output is correct
33 Correct 16 ms 12064 KB Output is correct
34 Correct 15 ms 12176 KB Output is correct
35 Correct 16 ms 12116 KB Output is correct
36 Correct 23 ms 12076 KB Output is correct
37 Correct 16 ms 12160 KB Output is correct
38 Correct 14 ms 12116 KB Output is correct
39 Correct 29 ms 15264 KB Output is correct
40 Correct 28 ms 15144 KB Output is correct
41 Correct 35 ms 15224 KB Output is correct
42 Correct 7 ms 8020 KB Output is correct
43 Correct 5 ms 8020 KB Output is correct
44 Correct 5 ms 8104 KB Output is correct
45 Correct 5 ms 8148 KB Output is correct
46 Correct 6 ms 8404 KB Output is correct
47 Correct 7 ms 8236 KB Output is correct
48 Correct 5 ms 8276 KB Output is correct
49 Correct 6 ms 8292 KB Output is correct
50 Correct 6 ms 8276 KB Output is correct
51 Correct 7 ms 8148 KB Output is correct
52 Correct 6 ms 8148 KB Output is correct
53 Correct 6 ms 8148 KB Output is correct
54 Correct 5 ms 8148 KB Output is correct
55 Correct 5 ms 8148 KB Output is correct
56 Correct 5 ms 8148 KB Output is correct
57 Correct 6 ms 8196 KB Output is correct
58 Correct 6 ms 8148 KB Output is correct
59 Correct 5 ms 8148 KB Output is correct
60 Correct 5 ms 8148 KB Output is correct
61 Correct 5 ms 8148 KB Output is correct
62 Correct 5 ms 8148 KB Output is correct
63 Correct 7 ms 8764 KB Output is correct
64 Correct 6 ms 8532 KB Output is correct
65 Correct 6 ms 8532 KB Output is correct
66 Correct 7 ms 8404 KB Output is correct
67 Correct 6 ms 8340 KB Output is correct
68 Correct 6 ms 8204 KB Output is correct
69 Correct 6 ms 8148 KB Output is correct
70 Correct 5 ms 8148 KB Output is correct
71 Correct 7 ms 8148 KB Output is correct
72 Correct 4 ms 8148 KB Output is correct
73 Correct 4 ms 8224 KB Output is correct
74 Correct 5 ms 8276 KB Output is correct
75 Correct 5 ms 8148 KB Output is correct
76 Correct 6 ms 8148 KB Output is correct
77 Correct 4 ms 8148 KB Output is correct
78 Correct 5 ms 8148 KB Output is correct
79 Correct 5 ms 8148 KB Output is correct
80 Correct 9 ms 10068 KB Output is correct
81 Correct 8 ms 8916 KB Output is correct
82 Correct 11 ms 10536 KB Output is correct
83 Correct 13 ms 9684 KB Output is correct
84 Correct 13 ms 10140 KB Output is correct
85 Correct 10 ms 8660 KB Output is correct
86 Correct 11 ms 8648 KB Output is correct
87 Correct 7 ms 8660 KB Output is correct
88 Correct 7 ms 8404 KB Output is correct
89 Correct 7 ms 8660 KB Output is correct
90 Correct 7 ms 8584 KB Output is correct
91 Correct 20 ms 10812 KB Output is correct
92 Correct 21 ms 11220 KB Output is correct
93 Correct 42 ms 11596 KB Output is correct
94 Correct 18 ms 12280 KB Output is correct
95 Correct 18 ms 12244 KB Output is correct
96 Correct 14 ms 12296 KB Output is correct
97 Correct 14 ms 12208 KB Output is correct
98 Correct 14 ms 12244 KB Output is correct
99 Correct 8 ms 8788 KB Output is correct
100 Correct 8 ms 8788 KB Output is correct
101 Correct 10 ms 8916 KB Output is correct
102 Correct 8 ms 8788 KB Output is correct
103 Correct 7 ms 8788 KB Output is correct
104 Correct 7 ms 8788 KB Output is correct
105 Correct 29 ms 11852 KB Output is correct
106 Correct 33 ms 11808 KB Output is correct
107 Correct 30 ms 11808 KB Output is correct
108 Correct 12 ms 11860 KB Output is correct
109 Correct 799 ms 415692 KB Output is correct
110 Correct 477 ms 212424 KB Output is correct
111 Correct 392 ms 169732 KB Output is correct
112 Correct 552 ms 203360 KB Output is correct
113 Correct 318 ms 125044 KB Output is correct
114 Correct 20 ms 11988 KB Output is correct
115 Correct 19 ms 11988 KB Output is correct
116 Correct 28 ms 13764 KB Output is correct
117 Correct 19 ms 11996 KB Output is correct
118 Correct 19 ms 12500 KB Output is correct
119 Correct 17 ms 12116 KB Output is correct
120 Correct 22 ms 12104 KB Output is correct
121 Correct 11 ms 10708 KB Output is correct
122 Correct 26 ms 12576 KB Output is correct
123 Correct 11 ms 10580 KB Output is correct
124 Correct 31 ms 13800 KB Output is correct
125 Correct 20 ms 12116 KB Output is correct
126 Correct 13 ms 11404 KB Output is correct
127 Correct 20 ms 12096 KB Output is correct
128 Correct 11 ms 10948 KB Output is correct
129 Correct 14 ms 11188 KB Output is correct
130 Correct 11 ms 11848 KB Output is correct
131 Runtime error 870 ms 524288 KB Execution killed with signal 9
132 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 7 ms 8020 KB Output is correct
3 Correct 6 ms 8020 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 4 ms 8020 KB Output is correct
6 Correct 5 ms 8020 KB Output is correct
7 Correct 6 ms 8020 KB Output is correct
8 Correct 5 ms 8016 KB Output is correct
9 Correct 6 ms 8020 KB Output is correct
10 Correct 5 ms 8020 KB Output is correct
11 Correct 5 ms 8148 KB Output is correct
12 Correct 4 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 5 ms 8148 KB Output is correct
15 Correct 7 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 4 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 9 ms 8148 KB Output is correct
21 Correct 5 ms 8148 KB Output is correct
22 Correct 5 ms 8148 KB Output is correct
23 Correct 5 ms 8164 KB Output is correct
24 Correct 37 ms 12068 KB Output is correct
25 Correct 22 ms 12116 KB Output is correct
26 Correct 21 ms 12116 KB Output is correct
27 Correct 5 ms 8276 KB Output is correct
28 Correct 6 ms 8276 KB Output is correct
29 Correct 14 ms 11240 KB Output is correct
30 Correct 9 ms 11208 KB Output is correct
31 Correct 10 ms 11240 KB Output is correct
32 Correct 13 ms 11240 KB Output is correct
33 Correct 16 ms 12064 KB Output is correct
34 Correct 15 ms 12176 KB Output is correct
35 Correct 16 ms 12116 KB Output is correct
36 Correct 23 ms 12076 KB Output is correct
37 Correct 16 ms 12160 KB Output is correct
38 Correct 14 ms 12116 KB Output is correct
39 Correct 29 ms 15264 KB Output is correct
40 Correct 28 ms 15144 KB Output is correct
41 Correct 35 ms 15224 KB Output is correct
42 Correct 11 ms 9096 KB Output is correct
43 Correct 9 ms 8700 KB Output is correct
44 Correct 28 ms 23444 KB Output is correct
45 Correct 21 ms 18312 KB Output is correct
46 Correct 19 ms 17428 KB Output is correct
47 Correct 33 ms 23540 KB Output is correct
48 Incorrect 61 ms 29676 KB Output isn't correct
49 Halted 0 ms 0 KB -