Submission #965746

# Submission time Handle Problem Language Result Execution time Memory
965746 2024-04-19T06:49:20 Z Darren0724 Painting Walls (APIO20_paint) C++17
28 / 100
1500 ms 19028 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B) {
  	vector<int> dp(N+1,INF);
	vector<unordered_set<int>> s(M);
	for(int i=0;i<M;i++){
		for(int j:B[i]){
			s[i].insert(j);
		}
	}
	auto check=[&](int st,int now)->int {
		for(int i=st;i<st+M;i++){
			if(!s[now].count(C[i]))return 0;
			now++;
			now%=M;
		}
		return 1;
	};	
	deque<int> d;
	d.push_back(0);
	dp[0]=0;
	for(int i=M;i<=N;i++){
		while(d.size()&&d.front()<i-M){
			d.pop_front();
		}
		int flag=0;
		for(int j=0;j<M;j++){
			flag|=check(i-M,j);
		}
		if(flag){
			dp[i]=dp[d.front()]+1;
		}
		while(d.size()&&dp[d.back()]>dp[i]){
			d.pop_back();
		}
		d.push_back(i);
	}
	return (dp[N]>=INF?-1:dp[N]);

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 412 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 444 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 440 KB Output is correct
22 Correct 17 ms 5748 KB Output is correct
23 Correct 17 ms 5604 KB Output is correct
24 Correct 17 ms 5724 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 3 ms 600 KB Output is correct
31 Correct 1421 ms 2156 KB Output is correct
32 Correct 1435 ms 2140 KB Output is correct
33 Correct 1439 ms 2140 KB Output is correct
34 Correct 1438 ms 2140 KB Output is correct
35 Correct 1432 ms 2388 KB Output is correct
36 Correct 1412 ms 2140 KB Output is correct
37 Correct 945 ms 6572 KB Output is correct
38 Correct 932 ms 6572 KB Output is correct
39 Correct 937 ms 6580 KB Output is correct
40 Correct 8 ms 1628 KB Output is correct
41 Correct 5 ms 1116 KB Output is correct
42 Correct 11 ms 1808 KB Output is correct
43 Correct 7 ms 1116 KB Output is correct
44 Correct 7 ms 1280 KB Output is correct
45 Correct 11 ms 1624 KB Output is correct
46 Execution timed out 1547 ms 19028 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 412 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 444 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 440 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 440 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 440 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 4 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 344 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 344 KB Output is correct
58 Correct 2 ms 344 KB Output is correct
59 Correct 2 ms 344 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 412 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 440 KB Output is correct
24 Correct 17 ms 5748 KB Output is correct
25 Correct 17 ms 5604 KB Output is correct
26 Correct 17 ms 5724 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 440 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 436 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 440 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 2 ms 344 KB Output is correct
61 Correct 2 ms 344 KB Output is correct
62 Correct 2 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 2 ms 348 KB Output is correct
65 Correct 21 ms 348 KB Output is correct
66 Correct 8 ms 440 KB Output is correct
67 Correct 64 ms 348 KB Output is correct
68 Correct 26 ms 344 KB Output is correct
69 Correct 57 ms 344 KB Output is correct
70 Correct 18 ms 1024 KB Output is correct
71 Correct 17 ms 1112 KB Output is correct
72 Correct 12 ms 860 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 14 ms 860 KB Output is correct
75 Correct 12 ms 932 KB Output is correct
76 Correct 17 ms 6488 KB Output is correct
77 Correct 17 ms 6840 KB Output is correct
78 Correct 22 ms 8028 KB Output is correct
79 Correct 103 ms 348 KB Output is correct
80 Correct 129 ms 344 KB Output is correct
81 Correct 139 ms 496 KB Output is correct
82 Correct 140 ms 500 KB Output is correct
83 Correct 144 ms 344 KB Output is correct
84 Correct 27 ms 1116 KB Output is correct
85 Correct 26 ms 1116 KB Output is correct
86 Correct 25 ms 1116 KB Output is correct
87 Correct 26 ms 1116 KB Output is correct
88 Correct 26 ms 1116 KB Output is correct
89 Correct 26 ms 1108 KB Output is correct
90 Correct 25 ms 9052 KB Output is correct
91 Correct 26 ms 9004 KB Output is correct
92 Correct 26 ms 9172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 412 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 440 KB Output is correct
24 Correct 17 ms 5748 KB Output is correct
25 Correct 17 ms 5604 KB Output is correct
26 Correct 17 ms 5724 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 1421 ms 2156 KB Output is correct
34 Correct 1435 ms 2140 KB Output is correct
35 Correct 1439 ms 2140 KB Output is correct
36 Correct 1438 ms 2140 KB Output is correct
37 Correct 1432 ms 2388 KB Output is correct
38 Correct 1412 ms 2140 KB Output is correct
39 Correct 945 ms 6572 KB Output is correct
40 Correct 932 ms 6572 KB Output is correct
41 Correct 937 ms 6580 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 440 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 436 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 344 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 440 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 4 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 2 ms 348 KB Output is correct
69 Correct 2 ms 348 KB Output is correct
70 Correct 2 ms 344 KB Output is correct
71 Correct 2 ms 348 KB Output is correct
72 Correct 2 ms 348 KB Output is correct
73 Correct 2 ms 348 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 2 ms 344 KB Output is correct
76 Correct 2 ms 344 KB Output is correct
77 Correct 2 ms 344 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 2 ms 348 KB Output is correct
80 Correct 21 ms 348 KB Output is correct
81 Correct 8 ms 440 KB Output is correct
82 Correct 64 ms 348 KB Output is correct
83 Correct 26 ms 344 KB Output is correct
84 Correct 57 ms 344 KB Output is correct
85 Correct 18 ms 1024 KB Output is correct
86 Correct 17 ms 1112 KB Output is correct
87 Correct 12 ms 860 KB Output is correct
88 Correct 3 ms 604 KB Output is correct
89 Correct 14 ms 860 KB Output is correct
90 Correct 12 ms 932 KB Output is correct
91 Correct 17 ms 6488 KB Output is correct
92 Correct 17 ms 6840 KB Output is correct
93 Correct 22 ms 8028 KB Output is correct
94 Correct 103 ms 348 KB Output is correct
95 Correct 129 ms 344 KB Output is correct
96 Correct 139 ms 496 KB Output is correct
97 Correct 140 ms 500 KB Output is correct
98 Correct 144 ms 344 KB Output is correct
99 Correct 27 ms 1116 KB Output is correct
100 Correct 26 ms 1116 KB Output is correct
101 Correct 25 ms 1116 KB Output is correct
102 Correct 26 ms 1116 KB Output is correct
103 Correct 26 ms 1116 KB Output is correct
104 Correct 26 ms 1108 KB Output is correct
105 Correct 25 ms 9052 KB Output is correct
106 Correct 26 ms 9004 KB Output is correct
107 Correct 26 ms 9172 KB Output is correct
108 Correct 2 ms 600 KB Output is correct
109 Execution timed out 1583 ms 604 KB Time limit exceeded
110 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 412 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 440 KB Output is correct
24 Correct 17 ms 5748 KB Output is correct
25 Correct 17 ms 5604 KB Output is correct
26 Correct 17 ms 5724 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 1421 ms 2156 KB Output is correct
34 Correct 1435 ms 2140 KB Output is correct
35 Correct 1439 ms 2140 KB Output is correct
36 Correct 1438 ms 2140 KB Output is correct
37 Correct 1432 ms 2388 KB Output is correct
38 Correct 1412 ms 2140 KB Output is correct
39 Correct 945 ms 6572 KB Output is correct
40 Correct 932 ms 6572 KB Output is correct
41 Correct 937 ms 6580 KB Output is correct
42 Correct 8 ms 1628 KB Output is correct
43 Correct 5 ms 1116 KB Output is correct
44 Correct 11 ms 1808 KB Output is correct
45 Correct 7 ms 1116 KB Output is correct
46 Correct 7 ms 1280 KB Output is correct
47 Correct 11 ms 1624 KB Output is correct
48 Execution timed out 1547 ms 19028 KB Time limit exceeded
49 Halted 0 ms 0 KB -