Submission #347981

# Submission time Handle Problem Language Result Execution time Memory
347981 2021-01-14T01:42:53 Z arnold518 Painting Walls (APIO20_paint) C++14
51 / 100
143 ms 160560 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;
		if(!chk[i]) continue;
		while(!DQ.empty() && DQ.front()<i-M) DQ.pop_front();
		if(DQ.empty()) continue;
		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 2668 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 4716 KB Output is correct
10 Correct 3 ms 4716 KB Output is correct
11 Correct 4 ms 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 4 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 4 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 2 ms 2796 KB Output is correct
20 Correct 2 ms 2796 KB Output is correct
21 Correct 2 ms 2796 KB Output is correct
22 Correct 25 ms 8556 KB Output is correct
23 Correct 26 ms 8556 KB Output is correct
24 Correct 25 ms 8556 KB Output is correct
25 Correct 41 ms 83308 KB Output is correct
26 Correct 41 ms 83308 KB Output is correct
27 Correct 42 ms 83328 KB Output is correct
28 Correct 43 ms 83328 KB Output is correct
29 Correct 45 ms 83308 KB Output is correct
30 Correct 40 ms 83308 KB Output is correct
31 Correct 47 ms 84204 KB Output is correct
32 Correct 48 ms 84204 KB Output is correct
33 Correct 55 ms 84204 KB Output is correct
34 Correct 49 ms 84204 KB Output is correct
35 Correct 48 ms 84260 KB Output is correct
36 Correct 48 ms 84268 KB Output is correct
37 Correct 70 ms 84076 KB Output is correct
38 Correct 71 ms 83948 KB Output is correct
39 Correct 71 ms 84076 KB Output is correct
40 Runtime error 23 ms 7020 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 2668 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 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 4 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 4 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 3 ms 4716 KB Output is correct
18 Correct 4 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 2 ms 2796 KB Output is correct
22 Correct 2 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 2 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 2 ms 2796 KB Output is correct
43 Correct 3 ms 3948 KB Output is correct
44 Correct 3 ms 4716 KB Output is correct
45 Correct 3 ms 4716 KB Output is correct
46 Correct 3 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 3 ms 4844 KB Output is correct
50 Correct 3 ms 4716 KB Output is correct
51 Correct 3 ms 4716 KB Output is correct
52 Correct 3 ms 4716 KB Output is correct
53 Correct 4 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 3 ms 4844 KB Output is correct
58 Correct 2 ms 2796 KB Output is correct
59 Correct 3 ms 4844 KB Output is correct
60 Correct 2 ms 2796 KB Output is correct
61 Correct 3 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 2668 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 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 4 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 4 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 3 ms 4716 KB Output is correct
18 Correct 4 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 2 ms 2796 KB Output is correct
22 Correct 2 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 25 ms 8556 KB Output is correct
25 Correct 26 ms 8556 KB Output is correct
26 Correct 25 ms 8556 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 2 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 2 ms 2796 KB Output is correct
46 Correct 3 ms 3948 KB Output is correct
47 Correct 3 ms 4716 KB Output is correct
48 Correct 3 ms 4716 KB Output is correct
49 Correct 3 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 3 ms 4844 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 4 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 3 ms 4844 KB Output is correct
61 Correct 2 ms 2796 KB Output is correct
62 Correct 3 ms 4844 KB Output is correct
63 Correct 2 ms 2796 KB Output is correct
64 Correct 3 ms 4844 KB Output is correct
65 Correct 3 ms 3948 KB Output is correct
66 Correct 3 ms 4716 KB Output is correct
67 Correct 3 ms 4844 KB Output is correct
68 Correct 3 ms 4844 KB Output is correct
69 Correct 4 ms 4716 KB Output is correct
70 Correct 5 ms 4844 KB Output is correct
71 Correct 5 ms 4716 KB Output is correct
72 Correct 5 ms 4588 KB Output is correct
73 Correct 4 ms 4332 KB Output is correct
74 Correct 4 ms 4332 KB Output is correct
75 Correct 4 ms 4460 KB Output is correct
76 Correct 28 ms 6252 KB Output is correct
77 Correct 25 ms 6892 KB Output is correct
78 Correct 33 ms 7276 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 5 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 6 ms 5356 KB Output is correct
90 Correct 43 ms 8556 KB Output is correct
91 Correct 38 ms 8428 KB Output is correct
92 Correct 40 ms 8556 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 2668 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 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 4 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 4 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 3 ms 4716 KB Output is correct
18 Correct 4 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 2 ms 2796 KB Output is correct
22 Correct 2 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 25 ms 8556 KB Output is correct
25 Correct 26 ms 8556 KB Output is correct
26 Correct 25 ms 8556 KB Output is correct
27 Correct 41 ms 83308 KB Output is correct
28 Correct 41 ms 83308 KB Output is correct
29 Correct 42 ms 83328 KB Output is correct
30 Correct 43 ms 83328 KB Output is correct
31 Correct 45 ms 83308 KB Output is correct
32 Correct 40 ms 83308 KB Output is correct
33 Correct 47 ms 84204 KB Output is correct
34 Correct 48 ms 84204 KB Output is correct
35 Correct 55 ms 84204 KB Output is correct
36 Correct 49 ms 84204 KB Output is correct
37 Correct 48 ms 84260 KB Output is correct
38 Correct 48 ms 84268 KB Output is correct
39 Correct 70 ms 84076 KB Output is correct
40 Correct 71 ms 83948 KB Output is correct
41 Correct 71 ms 84076 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 2 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 2 ms 2796 KB Output is correct
61 Correct 3 ms 3948 KB Output is correct
62 Correct 3 ms 4716 KB Output is correct
63 Correct 3 ms 4716 KB Output is correct
64 Correct 3 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 3 ms 4844 KB Output is correct
68 Correct 3 ms 4716 KB Output is correct
69 Correct 3 ms 4716 KB Output is correct
70 Correct 3 ms 4716 KB Output is correct
71 Correct 4 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 3 ms 4844 KB Output is correct
76 Correct 2 ms 2796 KB Output is correct
77 Correct 3 ms 4844 KB Output is correct
78 Correct 2 ms 2796 KB Output is correct
79 Correct 3 ms 4844 KB Output is correct
80 Correct 3 ms 3948 KB Output is correct
81 Correct 3 ms 4716 KB Output is correct
82 Correct 3 ms 4844 KB Output is correct
83 Correct 3 ms 4844 KB Output is correct
84 Correct 4 ms 4716 KB Output is correct
85 Correct 5 ms 4844 KB Output is correct
86 Correct 5 ms 4716 KB Output is correct
87 Correct 5 ms 4588 KB Output is correct
88 Correct 4 ms 4332 KB Output is correct
89 Correct 4 ms 4332 KB Output is correct
90 Correct 4 ms 4460 KB Output is correct
91 Correct 28 ms 6252 KB Output is correct
92 Correct 25 ms 6892 KB Output is correct
93 Correct 33 ms 7276 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 5 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 6 ms 5356 KB Output is correct
105 Correct 43 ms 8556 KB Output is correct
106 Correct 38 ms 8428 KB Output is correct
107 Correct 40 ms 8556 KB Output is correct
108 Correct 46 ms 82924 KB Output is correct
109 Correct 98 ms 96236 KB Output is correct
110 Correct 86 ms 83052 KB Output is correct
111 Correct 74 ms 79468 KB Output is correct
112 Correct 95 ms 108396 KB Output is correct
113 Correct 69 ms 85996 KB Output is correct
114 Correct 54 ms 77676 KB Output is correct
115 Correct 40 ms 46592 KB Output is correct
116 Correct 73 ms 110060 KB Output is correct
117 Correct 49 ms 68076 KB Output is correct
118 Correct 48 ms 58092 KB Output is correct
119 Correct 63 ms 100204 KB Output is correct
120 Correct 52 ms 53376 KB Output is correct
121 Correct 42 ms 69100 KB Output is correct
122 Correct 55 ms 53100 KB Output is correct
123 Correct 35 ms 56044 KB Output is correct
124 Correct 67 ms 68332 KB Output is correct
125 Correct 51 ms 81772 KB Output is correct
126 Correct 41 ms 66284 KB Output is correct
127 Correct 53 ms 85996 KB Output is correct
128 Correct 37 ms 59116 KB Output is correct
129 Correct 39 ms 62188 KB Output is correct
130 Correct 45 ms 83436 KB Output is correct
131 Correct 133 ms 132716 KB Output is correct
132 Correct 143 ms 145900 KB Output is correct
133 Correct 143 ms 153964 KB Output is correct
134 Correct 137 ms 160364 KB Output is correct
135 Correct 130 ms 160560 KB Output is correct
136 Correct 99 ms 159724 KB Output is correct
137 Correct 91 ms 149868 KB Output is correct
138 Correct 95 ms 153836 KB Output is correct
139 Correct 92 ms 149868 KB Output is correct
140 Correct 93 ms 153452 KB Output is correct
141 Correct 95 ms 157676 KB Output is correct
142 Correct 93 ms 94060 KB Output is correct
143 Correct 67 ms 114668 KB Output is correct
144 Correct 92 ms 93420 KB Output is correct
145 Correct 68 ms 115176 KB Output is correct
146 Correct 92 ms 94188 KB Output is correct
147 Correct 69 ms 115308 KB Output is correct
148 Correct 60 ms 99436 KB Output is correct
149 Correct 62 ms 99692 KB Output is correct
150 Correct 57 ms 92908 KB Output is correct
151 Correct 56 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 2668 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 4716 KB Output is correct
12 Correct 3 ms 4716 KB Output is correct
13 Correct 4 ms 4716 KB Output is correct
14 Correct 3 ms 4716 KB Output is correct
15 Correct 4 ms 4716 KB Output is correct
16 Correct 3 ms 4716 KB Output is correct
17 Correct 3 ms 4716 KB Output is correct
18 Correct 4 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 2 ms 2796 KB Output is correct
22 Correct 2 ms 2796 KB Output is correct
23 Correct 2 ms 2796 KB Output is correct
24 Correct 25 ms 8556 KB Output is correct
25 Correct 26 ms 8556 KB Output is correct
26 Correct 25 ms 8556 KB Output is correct
27 Correct 41 ms 83308 KB Output is correct
28 Correct 41 ms 83308 KB Output is correct
29 Correct 42 ms 83328 KB Output is correct
30 Correct 43 ms 83328 KB Output is correct
31 Correct 45 ms 83308 KB Output is correct
32 Correct 40 ms 83308 KB Output is correct
33 Correct 47 ms 84204 KB Output is correct
34 Correct 48 ms 84204 KB Output is correct
35 Correct 55 ms 84204 KB Output is correct
36 Correct 49 ms 84204 KB Output is correct
37 Correct 48 ms 84260 KB Output is correct
38 Correct 48 ms 84268 KB Output is correct
39 Correct 70 ms 84076 KB Output is correct
40 Correct 71 ms 83948 KB Output is correct
41 Correct 71 ms 84076 KB Output is correct
42 Runtime error 23 ms 7020 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Halted 0 ms 0 KB -