Submission #347980

# Submission time Handle Problem Language Result Execution time Memory
347980 2021-01-14T01:41:33 Z arnold518 Painting Walls (APIO20_paint) C++14
51 / 100
145 ms 160492 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e4;
const int MAXM = 2000;
const int MAXK = 1e5;

int N, M, K;
int C[MAXN+10];
vector<int> B[MAXK+10];

int dp[MAXN+10][MAXM+10], chk[MAXN+10];
int dp2[MAXN+10];

int minimumInstructions(int _N, int _M, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B)
{
	N=_N; M=_M; K=_K;
	for(int i=0; i<N; i++) C[i]=_C[i];
	for(int i=0; i<M; i++)
	{
		for(auto it : _B[i])
		{
			B[it].push_back(i);
		}
	}

	for(int i=0; i<N; i++)
	{
		for(auto it : B[C[i]])
		{
			dp[i][it]=1;
			if(i!=0 && dp[i-1][(it+M-1)%M])
			{
				dp[i][it]=dp[i-1][(it+M-1)%M]+1;
			}
			if(dp[i][it]>=M)
			{
				chk[i+1]=1;
			}
		}
	}
/*
	for(int i=0; i<M; i++)
	{
		for(int j=0; j<N; j++)
		{
			printf("%d ", dp[j][i]);
		}
		printf("\n");
	}

*/	

	for(int i=1; i<=N; i++)
	{
		dp2[i]=987654321;
		if(!chk[i]) continue;
		for(int j=max(i-M, 0); j<i; j++)
		{
			dp2[i]=min(dp2[i], dp2[j]+1);
		}
	}

/*
	deque<int> DQ;
	DQ.push_back(0);
	for(int i=1; i<=N; i++)
	{
		dp2[i]=987654321;
		while(!DQ.empty() && DQ.front()<i-M) DQ.pop_front();
		if(chk[i] && !DQ.empty())
		{
			dp2[i]=dp2[DQ.front()]+1;	
		}
		while(!DQ.empty() && dp2[DQ.back()]>=dp2[i]) DQ.pop_back();
		DQ.push_back(i);
		//printf("%d ", dp2[i]);
	}
*/
	if(dp2[N]==987654321) return -1;
	return dp2[N];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 3 ms 4716 KB Output is correct
8 Correct 3 ms 4716 KB Output is correct
9 Correct 3 ms 4736 KB Output is correct
10 Correct 3 ms 4728 KB Output is correct
11 Correct 3 ms 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 3 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 4 ms 4844 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 3 ms 4716 KB Output is correct
18 Correct 3 ms 4716 KB Output is correct
19 Correct 3 ms 2816 KB Output is correct
20 Correct 3 ms 2796 KB Output is correct
21 Correct 2 ms 2796 KB Output is correct
22 Correct 26 ms 9196 KB Output is correct
23 Correct 26 ms 9196 KB Output is correct
24 Correct 27 ms 9196 KB Output is correct
25 Correct 40 ms 83436 KB Output is correct
26 Correct 40 ms 83436 KB Output is correct
27 Correct 39 ms 83436 KB Output is correct
28 Correct 40 ms 83436 KB Output is correct
29 Correct 40 ms 83436 KB Output is correct
30 Correct 40 ms 83436 KB Output is correct
31 Correct 89 ms 84480 KB Output is correct
32 Correct 90 ms 84460 KB Output is correct
33 Correct 90 ms 84460 KB Output is correct
34 Correct 89 ms 84460 KB Output is correct
35 Correct 91 ms 84460 KB Output is correct
36 Correct 91 ms 84588 KB Output is correct
37 Correct 70 ms 84844 KB Output is correct
38 Correct 70 ms 84716 KB Output is correct
39 Correct 70 ms 84736 KB Output is correct
40 Runtime error 24 ms 7276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 3 ms 4716 KB Output is correct
10 Correct 3 ms 4716 KB Output is correct
11 Correct 3 ms 4736 KB Output is correct
12 Correct 3 ms 4728 KB Output is correct
13 Correct 3 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 3 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 4 ms 4844 KB Output is correct
18 Correct 3 ms 4716 KB Output is correct
19 Correct 3 ms 4716 KB Output is correct
20 Correct 3 ms 4716 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 3 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 2 ms 2668 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 2 ms 2668 KB Output is correct
27 Correct 3 ms 3820 KB Output is correct
28 Correct 3 ms 4076 KB Output is correct
29 Correct 4 ms 3692 KB Output is correct
30 Correct 3 ms 4076 KB Output is correct
31 Correct 3 ms 4460 KB Output is correct
32 Correct 3 ms 4204 KB Output is correct
33 Correct 3 ms 4332 KB Output is correct
34 Correct 3 ms 4460 KB Output is correct
35 Correct 3 ms 3820 KB Output is correct
36 Correct 3 ms 4204 KB Output is correct
37 Correct 3 ms 4076 KB Output is correct
38 Correct 2 ms 2668 KB Output is correct
39 Correct 3 ms 3948 KB Output is correct
40 Correct 2 ms 2796 KB Output is correct
41 Correct 3 ms 4076 KB Output is correct
42 Correct 3 ms 2796 KB Output is correct
43 Correct 3 ms 3948 KB Output is correct
44 Correct 4 ms 4716 KB Output is correct
45 Correct 3 ms 4716 KB Output is correct
46 Correct 4 ms 4716 KB Output is correct
47 Correct 3 ms 4844 KB Output is correct
48 Correct 3 ms 4844 KB Output is correct
49 Correct 4 ms 4844 KB Output is correct
50 Correct 4 ms 4716 KB Output is correct
51 Correct 3 ms 4716 KB Output is correct
52 Correct 4 ms 4716 KB Output is correct
53 Correct 3 ms 4716 KB Output is correct
54 Correct 3 ms 4716 KB Output is correct
55 Correct 3 ms 4716 KB Output is correct
56 Correct 2 ms 2796 KB Output is correct
57 Correct 4 ms 4844 KB Output is correct
58 Correct 2 ms 2816 KB Output is correct
59 Correct 4 ms 4844 KB Output is correct
60 Correct 2 ms 2796 KB Output is correct
61 Correct 4 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 3 ms 4716 KB Output is correct
10 Correct 3 ms 4716 KB Output is correct
11 Correct 3 ms 4736 KB Output is correct
12 Correct 3 ms 4728 KB Output is correct
13 Correct 3 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 3 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 4 ms 4844 KB Output is correct
18 Correct 3 ms 4716 KB Output is correct
19 Correct 3 ms 4716 KB Output is correct
20 Correct 3 ms 4716 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 3 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 26 ms 9196 KB Output is correct
25 Correct 26 ms 9196 KB Output is correct
26 Correct 27 ms 9196 KB Output is correct
27 Correct 2 ms 2668 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 2 ms 2668 KB Output is correct
30 Correct 3 ms 3820 KB Output is correct
31 Correct 3 ms 4076 KB Output is correct
32 Correct 4 ms 3692 KB Output is correct
33 Correct 3 ms 4076 KB Output is correct
34 Correct 3 ms 4460 KB Output is correct
35 Correct 3 ms 4204 KB Output is correct
36 Correct 3 ms 4332 KB Output is correct
37 Correct 3 ms 4460 KB Output is correct
38 Correct 3 ms 3820 KB Output is correct
39 Correct 3 ms 4204 KB Output is correct
40 Correct 3 ms 4076 KB Output is correct
41 Correct 2 ms 2668 KB Output is correct
42 Correct 3 ms 3948 KB Output is correct
43 Correct 2 ms 2796 KB Output is correct
44 Correct 3 ms 4076 KB Output is correct
45 Correct 3 ms 2796 KB Output is correct
46 Correct 3 ms 3948 KB Output is correct
47 Correct 4 ms 4716 KB Output is correct
48 Correct 3 ms 4716 KB Output is correct
49 Correct 4 ms 4716 KB Output is correct
50 Correct 3 ms 4844 KB Output is correct
51 Correct 3 ms 4844 KB Output is correct
52 Correct 4 ms 4844 KB Output is correct
53 Correct 4 ms 4716 KB Output is correct
54 Correct 3 ms 4716 KB Output is correct
55 Correct 4 ms 4716 KB Output is correct
56 Correct 3 ms 4716 KB Output is correct
57 Correct 3 ms 4716 KB Output is correct
58 Correct 3 ms 4716 KB Output is correct
59 Correct 2 ms 2796 KB Output is correct
60 Correct 4 ms 4844 KB Output is correct
61 Correct 2 ms 2816 KB Output is correct
62 Correct 4 ms 4844 KB Output is correct
63 Correct 2 ms 2796 KB Output is correct
64 Correct 4 ms 4844 KB Output is correct
65 Correct 3 ms 3948 KB Output is correct
66 Correct 4 ms 4716 KB Output is correct
67 Correct 4 ms 4972 KB Output is correct
68 Correct 4 ms 4844 KB Output is correct
69 Correct 4 ms 4716 KB Output is correct
70 Correct 5 ms 4972 KB Output is correct
71 Correct 6 ms 4844 KB Output is correct
72 Correct 5 ms 4588 KB Output is correct
73 Correct 4 ms 4332 KB Output is correct
74 Correct 5 ms 4480 KB Output is correct
75 Correct 4 ms 4460 KB Output is correct
76 Correct 27 ms 6892 KB Output is correct
77 Correct 25 ms 7660 KB Output is correct
78 Correct 34 ms 8044 KB Output is correct
79 Correct 4 ms 5100 KB Output is correct
80 Correct 4 ms 5100 KB Output is correct
81 Correct 4 ms 5100 KB Output is correct
82 Correct 4 ms 5100 KB Output is correct
83 Correct 4 ms 5100 KB Output is correct
84 Correct 6 ms 5356 KB Output is correct
85 Correct 6 ms 5356 KB Output is correct
86 Correct 6 ms 5356 KB Output is correct
87 Correct 6 ms 5356 KB Output is correct
88 Correct 6 ms 5356 KB Output is correct
89 Correct 7 ms 5356 KB Output is correct
90 Correct 41 ms 8940 KB Output is correct
91 Correct 39 ms 8940 KB Output is correct
92 Correct 38 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 3 ms 4716 KB Output is correct
10 Correct 3 ms 4716 KB Output is correct
11 Correct 3 ms 4736 KB Output is correct
12 Correct 3 ms 4728 KB Output is correct
13 Correct 3 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 3 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 4 ms 4844 KB Output is correct
18 Correct 3 ms 4716 KB Output is correct
19 Correct 3 ms 4716 KB Output is correct
20 Correct 3 ms 4716 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 3 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 26 ms 9196 KB Output is correct
25 Correct 26 ms 9196 KB Output is correct
26 Correct 27 ms 9196 KB Output is correct
27 Correct 40 ms 83436 KB Output is correct
28 Correct 40 ms 83436 KB Output is correct
29 Correct 39 ms 83436 KB Output is correct
30 Correct 40 ms 83436 KB Output is correct
31 Correct 40 ms 83436 KB Output is correct
32 Correct 40 ms 83436 KB Output is correct
33 Correct 89 ms 84480 KB Output is correct
34 Correct 90 ms 84460 KB Output is correct
35 Correct 90 ms 84460 KB Output is correct
36 Correct 89 ms 84460 KB Output is correct
37 Correct 91 ms 84460 KB Output is correct
38 Correct 91 ms 84588 KB Output is correct
39 Correct 70 ms 84844 KB Output is correct
40 Correct 70 ms 84716 KB Output is correct
41 Correct 70 ms 84736 KB Output is correct
42 Correct 2 ms 2668 KB Output is correct
43 Correct 2 ms 2668 KB Output is correct
44 Correct 2 ms 2668 KB Output is correct
45 Correct 3 ms 3820 KB Output is correct
46 Correct 3 ms 4076 KB Output is correct
47 Correct 4 ms 3692 KB Output is correct
48 Correct 3 ms 4076 KB Output is correct
49 Correct 3 ms 4460 KB Output is correct
50 Correct 3 ms 4204 KB Output is correct
51 Correct 3 ms 4332 KB Output is correct
52 Correct 3 ms 4460 KB Output is correct
53 Correct 3 ms 3820 KB Output is correct
54 Correct 3 ms 4204 KB Output is correct
55 Correct 3 ms 4076 KB Output is correct
56 Correct 2 ms 2668 KB Output is correct
57 Correct 3 ms 3948 KB Output is correct
58 Correct 2 ms 2796 KB Output is correct
59 Correct 3 ms 4076 KB Output is correct
60 Correct 3 ms 2796 KB Output is correct
61 Correct 3 ms 3948 KB Output is correct
62 Correct 4 ms 4716 KB Output is correct
63 Correct 3 ms 4716 KB Output is correct
64 Correct 4 ms 4716 KB Output is correct
65 Correct 3 ms 4844 KB Output is correct
66 Correct 3 ms 4844 KB Output is correct
67 Correct 4 ms 4844 KB Output is correct
68 Correct 4 ms 4716 KB Output is correct
69 Correct 3 ms 4716 KB Output is correct
70 Correct 4 ms 4716 KB Output is correct
71 Correct 3 ms 4716 KB Output is correct
72 Correct 3 ms 4716 KB Output is correct
73 Correct 3 ms 4716 KB Output is correct
74 Correct 2 ms 2796 KB Output is correct
75 Correct 4 ms 4844 KB Output is correct
76 Correct 2 ms 2816 KB Output is correct
77 Correct 4 ms 4844 KB Output is correct
78 Correct 2 ms 2796 KB Output is correct
79 Correct 4 ms 4844 KB Output is correct
80 Correct 3 ms 3948 KB Output is correct
81 Correct 4 ms 4716 KB Output is correct
82 Correct 4 ms 4972 KB Output is correct
83 Correct 4 ms 4844 KB Output is correct
84 Correct 4 ms 4716 KB Output is correct
85 Correct 5 ms 4972 KB Output is correct
86 Correct 6 ms 4844 KB Output is correct
87 Correct 5 ms 4588 KB Output is correct
88 Correct 4 ms 4332 KB Output is correct
89 Correct 5 ms 4480 KB Output is correct
90 Correct 4 ms 4460 KB Output is correct
91 Correct 27 ms 6892 KB Output is correct
92 Correct 25 ms 7660 KB Output is correct
93 Correct 34 ms 8044 KB Output is correct
94 Correct 4 ms 5100 KB Output is correct
95 Correct 4 ms 5100 KB Output is correct
96 Correct 4 ms 5100 KB Output is correct
97 Correct 4 ms 5100 KB Output is correct
98 Correct 4 ms 5100 KB Output is correct
99 Correct 6 ms 5356 KB Output is correct
100 Correct 6 ms 5356 KB Output is correct
101 Correct 6 ms 5356 KB Output is correct
102 Correct 6 ms 5356 KB Output is correct
103 Correct 6 ms 5356 KB Output is correct
104 Correct 7 ms 5356 KB Output is correct
105 Correct 41 ms 8940 KB Output is correct
106 Correct 39 ms 8940 KB Output is correct
107 Correct 38 ms 9068 KB Output is correct
108 Correct 40 ms 82924 KB Output is correct
109 Correct 104 ms 96236 KB Output is correct
110 Correct 78 ms 83056 KB Output is correct
111 Correct 68 ms 79468 KB Output is correct
112 Correct 90 ms 108396 KB Output is correct
113 Correct 64 ms 85996 KB Output is correct
114 Correct 63 ms 77776 KB Output is correct
115 Correct 37 ms 46700 KB Output is correct
116 Correct 88 ms 110188 KB Output is correct
117 Correct 55 ms 68204 KB Output is correct
118 Correct 45 ms 58220 KB Output is correct
119 Correct 81 ms 100208 KB Output is correct
120 Correct 49 ms 53632 KB Output is correct
121 Correct 61 ms 69100 KB Output is correct
122 Correct 52 ms 53356 KB Output is correct
123 Correct 39 ms 56044 KB Output is correct
124 Correct 63 ms 68844 KB Output is correct
125 Correct 49 ms 81772 KB Output is correct
126 Correct 36 ms 66284 KB Output is correct
127 Correct 51 ms 85996 KB Output is correct
128 Correct 33 ms 59116 KB Output is correct
129 Correct 35 ms 62136 KB Output is correct
130 Correct 40 ms 83404 KB Output is correct
131 Correct 145 ms 132752 KB Output is correct
132 Correct 142 ms 145900 KB Output is correct
133 Correct 141 ms 153964 KB Output is correct
134 Correct 134 ms 160492 KB Output is correct
135 Correct 126 ms 160492 KB Output is correct
136 Correct 136 ms 159980 KB Output is correct
137 Correct 132 ms 150100 KB Output is correct
138 Correct 138 ms 154092 KB Output is correct
139 Correct 133 ms 150124 KB Output is correct
140 Correct 136 ms 153580 KB Output is correct
141 Correct 138 ms 157932 KB Output is correct
142 Correct 88 ms 94700 KB Output is correct
143 Correct 108 ms 114668 KB Output is correct
144 Correct 92 ms 94060 KB Output is correct
145 Correct 110 ms 115180 KB Output is correct
146 Correct 89 ms 94828 KB Output is correct
147 Correct 110 ms 115308 KB Output is correct
148 Correct 58 ms 99436 KB Output is correct
149 Correct 60 ms 99692 KB Output is correct
150 Correct 55 ms 92908 KB Output is correct
151 Correct 52 ms 90604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 3 ms 4716 KB Output is correct
10 Correct 3 ms 4716 KB Output is correct
11 Correct 3 ms 4736 KB Output is correct
12 Correct 3 ms 4728 KB Output is correct
13 Correct 3 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 3 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 4 ms 4844 KB Output is correct
18 Correct 3 ms 4716 KB Output is correct
19 Correct 3 ms 4716 KB Output is correct
20 Correct 3 ms 4716 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 3 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 26 ms 9196 KB Output is correct
25 Correct 26 ms 9196 KB Output is correct
26 Correct 27 ms 9196 KB Output is correct
27 Correct 40 ms 83436 KB Output is correct
28 Correct 40 ms 83436 KB Output is correct
29 Correct 39 ms 83436 KB Output is correct
30 Correct 40 ms 83436 KB Output is correct
31 Correct 40 ms 83436 KB Output is correct
32 Correct 40 ms 83436 KB Output is correct
33 Correct 89 ms 84480 KB Output is correct
34 Correct 90 ms 84460 KB Output is correct
35 Correct 90 ms 84460 KB Output is correct
36 Correct 89 ms 84460 KB Output is correct
37 Correct 91 ms 84460 KB Output is correct
38 Correct 91 ms 84588 KB Output is correct
39 Correct 70 ms 84844 KB Output is correct
40 Correct 70 ms 84716 KB Output is correct
41 Correct 70 ms 84736 KB Output is correct
42 Runtime error 24 ms 7276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Halted 0 ms 0 KB -