답안 #733235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733235 2023-04-30T09:34:47 Z bin9638 벽 칠하기 (APIO20_paint) C++17
51 / 100
189 ms 24528 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

int mp[2][20020];
int n,m,k,color[N],dp[N];
vector<int>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--)
    {
        memset(mp[(i&1)],0,sizeof(mp[(i&1)]));
        for(auto u:lis[color[i]])
            if(mp[(i+1)&1][(u+1)%m]!=0)
                mp[(i&1)][u]=min(m,mp[(i+1)&1][(u+1)%m]+1);
                    else mp[(i&1)][u]=1;
        for(auto u:lis[color[i]])
            if(mp[(i&1)][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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 4 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 3 ms 2772 KB Output is correct
13 Correct 3 ms 2792 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 4 ms 2772 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 4 ms 2772 KB Output is correct
19 Correct 5 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2876 KB Output is correct
22 Correct 24 ms 6732 KB Output is correct
23 Correct 27 ms 6652 KB Output is correct
24 Correct 23 ms 6732 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 44 ms 3076 KB Output is correct
28 Correct 66 ms 3088 KB Output is correct
29 Correct 52 ms 3096 KB Output is correct
30 Correct 49 ms 3076 KB Output is correct
31 Correct 53 ms 4008 KB Output is correct
32 Correct 53 ms 3992 KB Output is correct
33 Correct 99 ms 3980 KB Output is correct
34 Correct 74 ms 4024 KB Output is correct
35 Correct 44 ms 3996 KB Output is correct
36 Correct 44 ms 3924 KB Output is correct
37 Correct 57 ms 7104 KB Output is correct
38 Correct 55 ms 7124 KB Output is correct
39 Correct 83 ms 6992 KB Output is correct
40 Correct 9 ms 3668 KB Output is correct
41 Correct 6 ms 3284 KB Output is correct
42 Correct 189 ms 4312 KB Output is correct
43 Correct 136 ms 3720 KB Output is correct
44 Correct 131 ms 3700 KB Output is correct
45 Correct 181 ms 4256 KB Output is correct
46 Runtime error 65 ms 24528 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 4 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 3 ms 2772 KB Output is correct
13 Correct 3 ms 2792 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 4 ms 2772 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 4 ms 2772 KB Output is correct
19 Correct 5 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 3 ms 2876 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
25 Correct 2 ms 2764 KB Output is correct
26 Correct 2 ms 2772 KB Output is correct
27 Correct 4 ms 2804 KB Output is correct
28 Correct 4 ms 2772 KB Output is correct
29 Correct 4 ms 2820 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2772 KB Output is correct
43 Correct 2 ms 2772 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 5 ms 2772 KB Output is correct
49 Correct 3 ms 2772 KB Output is correct
50 Correct 4 ms 2772 KB Output is correct
51 Correct 4 ms 2772 KB Output is correct
52 Correct 3 ms 2772 KB Output is correct
53 Correct 3 ms 2772 KB Output is correct
54 Correct 5 ms 2772 KB Output is correct
55 Correct 3 ms 2772 KB Output is correct
56 Correct 3 ms 2772 KB Output is correct
57 Correct 3 ms 2772 KB Output is correct
58 Correct 4 ms 2772 KB Output is correct
59 Correct 3 ms 2772 KB Output is correct
60 Correct 3 ms 2772 KB Output is correct
61 Correct 4 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 3 ms 2792 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
21 Correct 5 ms 2772 KB Output is correct
22 Correct 3 ms 2772 KB Output is correct
23 Correct 3 ms 2876 KB Output is correct
24 Correct 24 ms 6732 KB Output is correct
25 Correct 27 ms 6652 KB Output is correct
26 Correct 23 ms 6732 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2764 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 4 ms 2804 KB Output is correct
31 Correct 4 ms 2772 KB Output is correct
32 Correct 4 ms 2820 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 2 ms 2772 KB Output is correct
43 Correct 3 ms 2772 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 2 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 3 ms 2772 KB Output is correct
49 Correct 3 ms 2772 KB Output is correct
50 Correct 3 ms 2772 KB Output is correct
51 Correct 5 ms 2772 KB Output is correct
52 Correct 3 ms 2772 KB Output is correct
53 Correct 4 ms 2772 KB Output is correct
54 Correct 4 ms 2772 KB Output is correct
55 Correct 3 ms 2772 KB Output is correct
56 Correct 3 ms 2772 KB Output is correct
57 Correct 5 ms 2772 KB Output is correct
58 Correct 3 ms 2772 KB Output is correct
59 Correct 3 ms 2772 KB Output is correct
60 Correct 3 ms 2772 KB Output is correct
61 Correct 4 ms 2772 KB Output is correct
62 Correct 3 ms 2772 KB Output is correct
63 Correct 3 ms 2772 KB Output is correct
64 Correct 4 ms 2772 KB Output is correct
65 Correct 4 ms 2772 KB Output is correct
66 Correct 4 ms 2772 KB Output is correct
67 Correct 3 ms 2772 KB Output is correct
68 Correct 4 ms 2772 KB Output is correct
69 Correct 4 ms 2772 KB Output is correct
70 Correct 4 ms 2900 KB Output is correct
71 Correct 5 ms 2900 KB Output is correct
72 Correct 4 ms 2920 KB Output is correct
73 Correct 5 ms 2900 KB Output is correct
74 Correct 5 ms 2900 KB Output is correct
75 Correct 6 ms 3012 KB Output is correct
76 Correct 27 ms 5452 KB Output is correct
77 Correct 22 ms 5796 KB Output is correct
78 Correct 39 ms 6212 KB Output is correct
79 Correct 5 ms 2772 KB Output is correct
80 Correct 3 ms 2772 KB Output is correct
81 Correct 4 ms 2772 KB Output is correct
82 Correct 4 ms 2772 KB Output is correct
83 Correct 4 ms 2848 KB Output is correct
84 Correct 5 ms 2940 KB Output is correct
85 Correct 5 ms 2952 KB Output is correct
86 Correct 4 ms 3028 KB Output is correct
87 Correct 7 ms 3028 KB Output is correct
88 Correct 6 ms 3028 KB Output is correct
89 Correct 6 ms 3028 KB Output is correct
90 Correct 29 ms 6436 KB Output is correct
91 Correct 33 ms 6488 KB Output is correct
92 Correct 37 ms 6556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 3 ms 2792 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
21 Correct 5 ms 2772 KB Output is correct
22 Correct 3 ms 2772 KB Output is correct
23 Correct 3 ms 2876 KB Output is correct
24 Correct 24 ms 6732 KB Output is correct
25 Correct 27 ms 6652 KB Output is correct
26 Correct 23 ms 6732 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 44 ms 3076 KB Output is correct
30 Correct 66 ms 3088 KB Output is correct
31 Correct 52 ms 3096 KB Output is correct
32 Correct 49 ms 3076 KB Output is correct
33 Correct 53 ms 4008 KB Output is correct
34 Correct 53 ms 3992 KB Output is correct
35 Correct 99 ms 3980 KB Output is correct
36 Correct 74 ms 4024 KB Output is correct
37 Correct 44 ms 3996 KB Output is correct
38 Correct 44 ms 3924 KB Output is correct
39 Correct 57 ms 7104 KB Output is correct
40 Correct 55 ms 7124 KB Output is correct
41 Correct 83 ms 6992 KB Output is correct
42 Correct 2 ms 2772 KB Output is correct
43 Correct 2 ms 2764 KB Output is correct
44 Correct 2 ms 2772 KB Output is correct
45 Correct 4 ms 2804 KB Output is correct
46 Correct 4 ms 2772 KB Output is correct
47 Correct 4 ms 2820 KB Output is correct
48 Correct 2 ms 2772 KB Output is correct
49 Correct 3 ms 2772 KB Output is correct
50 Correct 3 ms 2772 KB Output is correct
51 Correct 3 ms 2772 KB Output is correct
52 Correct 3 ms 2772 KB Output is correct
53 Correct 3 ms 2772 KB Output is correct
54 Correct 3 ms 2772 KB Output is correct
55 Correct 3 ms 2772 KB Output is correct
56 Correct 3 ms 2772 KB Output is correct
57 Correct 2 ms 2772 KB Output is correct
58 Correct 3 ms 2772 KB Output is correct
59 Correct 3 ms 2772 KB Output is correct
60 Correct 3 ms 2772 KB Output is correct
61 Correct 2 ms 2772 KB Output is correct
62 Correct 3 ms 2772 KB Output is correct
63 Correct 3 ms 2772 KB Output is correct
64 Correct 3 ms 2772 KB Output is correct
65 Correct 3 ms 2772 KB Output is correct
66 Correct 5 ms 2772 KB Output is correct
67 Correct 3 ms 2772 KB Output is correct
68 Correct 4 ms 2772 KB Output is correct
69 Correct 4 ms 2772 KB Output is correct
70 Correct 3 ms 2772 KB Output is correct
71 Correct 3 ms 2772 KB Output is correct
72 Correct 5 ms 2772 KB Output is correct
73 Correct 3 ms 2772 KB Output is correct
74 Correct 3 ms 2772 KB Output is correct
75 Correct 3 ms 2772 KB Output is correct
76 Correct 4 ms 2772 KB Output is correct
77 Correct 3 ms 2772 KB Output is correct
78 Correct 3 ms 2772 KB Output is correct
79 Correct 4 ms 2772 KB Output is correct
80 Correct 4 ms 2772 KB Output is correct
81 Correct 4 ms 2772 KB Output is correct
82 Correct 3 ms 2772 KB Output is correct
83 Correct 4 ms 2772 KB Output is correct
84 Correct 4 ms 2772 KB Output is correct
85 Correct 4 ms 2900 KB Output is correct
86 Correct 5 ms 2900 KB Output is correct
87 Correct 4 ms 2920 KB Output is correct
88 Correct 5 ms 2900 KB Output is correct
89 Correct 5 ms 2900 KB Output is correct
90 Correct 6 ms 3012 KB Output is correct
91 Correct 27 ms 5452 KB Output is correct
92 Correct 22 ms 5796 KB Output is correct
93 Correct 39 ms 6212 KB Output is correct
94 Correct 5 ms 2772 KB Output is correct
95 Correct 3 ms 2772 KB Output is correct
96 Correct 4 ms 2772 KB Output is correct
97 Correct 4 ms 2772 KB Output is correct
98 Correct 4 ms 2848 KB Output is correct
99 Correct 5 ms 2940 KB Output is correct
100 Correct 5 ms 2952 KB Output is correct
101 Correct 4 ms 3028 KB Output is correct
102 Correct 7 ms 3028 KB Output is correct
103 Correct 6 ms 3028 KB Output is correct
104 Correct 6 ms 3028 KB Output is correct
105 Correct 29 ms 6436 KB Output is correct
106 Correct 33 ms 6488 KB Output is correct
107 Correct 37 ms 6556 KB Output is correct
108 Correct 55 ms 3092 KB Output is correct
109 Correct 96 ms 3204 KB Output is correct
110 Correct 69 ms 3020 KB Output is correct
111 Correct 54 ms 3028 KB Output is correct
112 Correct 74 ms 3084 KB Output is correct
113 Correct 46 ms 3028 KB Output is correct
114 Correct 49 ms 4136 KB Output is correct
115 Correct 39 ms 3992 KB Output is correct
116 Correct 58 ms 4240 KB Output is correct
117 Correct 35 ms 4100 KB Output is correct
118 Correct 44 ms 4176 KB Output is correct
119 Correct 50 ms 3920 KB Output is correct
120 Correct 41 ms 5228 KB Output is correct
121 Correct 27 ms 3352 KB Output is correct
122 Correct 44 ms 5496 KB Output is correct
123 Correct 30 ms 3332 KB Output is correct
124 Correct 66 ms 6028 KB Output is correct
125 Correct 45 ms 3540 KB Output is correct
126 Correct 45 ms 3700 KB Output is correct
127 Correct 49 ms 3888 KB Output is correct
128 Correct 49 ms 3588 KB Output is correct
129 Correct 33 ms 3636 KB Output is correct
130 Correct 61 ms 3052 KB Output is correct
131 Correct 117 ms 3280 KB Output is correct
132 Correct 91 ms 3176 KB Output is correct
133 Correct 88 ms 3188 KB Output is correct
134 Correct 97 ms 3204 KB Output is correct
135 Correct 88 ms 3220 KB Output is correct
136 Correct 76 ms 5100 KB Output is correct
137 Correct 61 ms 5148 KB Output is correct
138 Correct 61 ms 5092 KB Output is correct
139 Correct 60 ms 5104 KB Output is correct
140 Correct 53 ms 5112 KB Output is correct
141 Correct 61 ms 5172 KB Output is correct
142 Correct 66 ms 7872 KB Output is correct
143 Correct 60 ms 4000 KB Output is correct
144 Correct 98 ms 7944 KB Output is correct
145 Correct 51 ms 3972 KB Output is correct
146 Correct 80 ms 7936 KB Output is correct
147 Correct 45 ms 4012 KB Output is correct
148 Correct 62 ms 4408 KB Output is correct
149 Correct 53 ms 4332 KB Output is correct
150 Correct 56 ms 4268 KB Output is correct
151 Correct 51 ms 4272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 3 ms 2792 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 3 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
21 Correct 5 ms 2772 KB Output is correct
22 Correct 3 ms 2772 KB Output is correct
23 Correct 3 ms 2876 KB Output is correct
24 Correct 24 ms 6732 KB Output is correct
25 Correct 27 ms 6652 KB Output is correct
26 Correct 23 ms 6732 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 44 ms 3076 KB Output is correct
30 Correct 66 ms 3088 KB Output is correct
31 Correct 52 ms 3096 KB Output is correct
32 Correct 49 ms 3076 KB Output is correct
33 Correct 53 ms 4008 KB Output is correct
34 Correct 53 ms 3992 KB Output is correct
35 Correct 99 ms 3980 KB Output is correct
36 Correct 74 ms 4024 KB Output is correct
37 Correct 44 ms 3996 KB Output is correct
38 Correct 44 ms 3924 KB Output is correct
39 Correct 57 ms 7104 KB Output is correct
40 Correct 55 ms 7124 KB Output is correct
41 Correct 83 ms 6992 KB Output is correct
42 Correct 9 ms 3668 KB Output is correct
43 Correct 6 ms 3284 KB Output is correct
44 Correct 189 ms 4312 KB Output is correct
45 Correct 136 ms 3720 KB Output is correct
46 Correct 131 ms 3700 KB Output is correct
47 Correct 181 ms 4256 KB Output is correct
48 Runtime error 65 ms 24528 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -