답안 #741435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741435 2023-05-14T05:16:00 Z penguin133 벽 칠하기 (APIO20_paint) C++17
51 / 100
1500 ms 19528 KB
#include <bits/stdc++.h>
using namespace std;
 
#include "paint.h"
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
bool ok[200005];
vector <int> brr[200005], grr[200005];
int dp[200005];
int stuf[200005];
 
int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {
  for(int i=0;i<M;i++){
	  for(auto j : B[i])brr[j].push_back(i);
  }
  set <int> ms;
  for(int i=0;i<M;i++)stuf[i] = M;
  for(int i=0;i<M-1;i++){
	for(auto j : brr[C[i]])stuf[(j - i + 1000 * M) % M]--;  
  }
  for(int i=M-1;i<N;i++){
	  for(auto j : brr[C[i]]){
		  stuf[(j - i + 1000 * M) % M]--;
		  int tmp = (j - i + 1000 * M)%M;
		  if(stuf[tmp] == 0)ms.insert(tmp);
	  }
	  int rv = i - (M - 1) - 1;
	  if(rv >= 0){
		  for(auto j : brr[C[rv]]){
			  stuf[(j - rv + 1000 * M) % M]++;
			  int tmp = (j - rv + 1000 * M) % M;
			  if(stuf[tmp] == 1)ms.erase(tmp);
		  }
	  }
	  if(!ms.empty())ok[i] = 1;
  }
  for(int i = 0; i < M - 1; i++)dp[i] = 2e9;
  deque <pi> dq;
  dq.push_back({0, -1});
  for(int i=M - 1;i<N;i++){
	  dp[i] = 2e9;
	  //cout << ok[i] << ' ';
	  if(!dq.empty() && dq.front().se < i - M)dq.pop_front();
	  if(ok[i]){
		  int tmp= 2e9;
		  if(i == M - 1)tmp = 0;
		  for(int j = i - 1; j >= max(0, i - M); j--)tmp = min(tmp, dp[j]);
		  dp[i] = tmp + 1;
	  }
	  while(!dq.empty() && dq.back().fi > dp[i])dq.pop_back();
	  dq.push_back({dp[i], i});
  }
  return (dp[N - 1] > N ? -1 : dp[N - 1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9636 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 6 ms 9776 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 25 ms 13516 KB Output is correct
23 Correct 22 ms 13560 KB Output is correct
24 Correct 25 ms 13644 KB Output is correct
25 Correct 8 ms 9940 KB Output is correct
26 Correct 9 ms 9940 KB Output is correct
27 Correct 8 ms 9956 KB Output is correct
28 Correct 8 ms 9940 KB Output is correct
29 Correct 8 ms 9904 KB Output is correct
30 Correct 8 ms 9940 KB Output is correct
31 Correct 51 ms 10856 KB Output is correct
32 Correct 55 ms 10836 KB Output is correct
33 Correct 48 ms 10896 KB Output is correct
34 Correct 48 ms 10860 KB Output is correct
35 Correct 49 ms 10892 KB Output is correct
36 Correct 48 ms 10864 KB Output is correct
37 Correct 28 ms 14036 KB Output is correct
38 Correct 29 ms 14036 KB Output is correct
39 Correct 28 ms 13952 KB Output is correct
40 Correct 16 ms 10756 KB Output is correct
41 Correct 15 ms 10324 KB Output is correct
42 Correct 20 ms 10964 KB Output is correct
43 Correct 13 ms 10480 KB Output is correct
44 Correct 12 ms 10452 KB Output is correct
45 Correct 17 ms 10880 KB Output is correct
46 Execution timed out 1584 ms 19528 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9636 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 6 ms 9776 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9616 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 6 ms 9684 KB Output is correct
30 Correct 5 ms 9720 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 7 ms 9724 KB Output is correct
33 Correct 5 ms 9720 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9744 KB Output is correct
38 Correct 5 ms 9684 KB Output is correct
39 Correct 5 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 7 ms 9684 KB Output is correct
42 Correct 6 ms 9636 KB Output is correct
43 Correct 5 ms 9684 KB Output is correct
44 Correct 6 ms 9684 KB Output is correct
45 Correct 6 ms 9724 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 5 ms 9684 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Correct 5 ms 9728 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 6 ms 9684 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9684 KB Output is correct
55 Correct 8 ms 9684 KB Output is correct
56 Correct 6 ms 9684 KB Output is correct
57 Correct 6 ms 9684 KB Output is correct
58 Correct 6 ms 9684 KB Output is correct
59 Correct 6 ms 9696 KB Output is correct
60 Correct 5 ms 9772 KB Output is correct
61 Correct 5 ms 9684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9636 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 6 ms 9776 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 25 ms 13516 KB Output is correct
25 Correct 22 ms 13560 KB Output is correct
26 Correct 25 ms 13644 KB Output is correct
27 Correct 5 ms 9616 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 5 ms 9684 KB Output is correct
30 Correct 6 ms 9684 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 5 ms 9720 KB Output is correct
34 Correct 6 ms 9684 KB Output is correct
35 Correct 7 ms 9724 KB Output is correct
36 Correct 5 ms 9720 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 5 ms 9684 KB Output is correct
40 Correct 5 ms 9744 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 6 ms 9684 KB Output is correct
44 Correct 7 ms 9684 KB Output is correct
45 Correct 6 ms 9636 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 6 ms 9684 KB Output is correct
48 Correct 6 ms 9724 KB Output is correct
49 Correct 5 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 5 ms 9728 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 6 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 5 ms 9684 KB Output is correct
57 Correct 6 ms 9684 KB Output is correct
58 Correct 8 ms 9684 KB Output is correct
59 Correct 6 ms 9684 KB Output is correct
60 Correct 6 ms 9684 KB Output is correct
61 Correct 6 ms 9684 KB Output is correct
62 Correct 6 ms 9696 KB Output is correct
63 Correct 5 ms 9772 KB Output is correct
64 Correct 5 ms 9684 KB Output is correct
65 Correct 6 ms 9728 KB Output is correct
66 Correct 6 ms 9616 KB Output is correct
67 Correct 6 ms 9684 KB Output is correct
68 Correct 5 ms 9684 KB Output is correct
69 Correct 7 ms 9684 KB Output is correct
70 Correct 6 ms 9812 KB Output is correct
71 Correct 6 ms 9812 KB Output is correct
72 Correct 7 ms 9812 KB Output is correct
73 Correct 7 ms 9824 KB Output is correct
74 Correct 7 ms 9812 KB Output is correct
75 Correct 6 ms 9812 KB Output is correct
76 Correct 24 ms 12372 KB Output is correct
77 Correct 21 ms 12764 KB Output is correct
78 Correct 27 ms 13140 KB Output is correct
79 Correct 7 ms 9668 KB Output is correct
80 Correct 7 ms 9736 KB Output is correct
81 Correct 7 ms 9684 KB Output is correct
82 Correct 7 ms 9684 KB Output is correct
83 Correct 7 ms 9684 KB Output is correct
84 Correct 7 ms 9836 KB Output is correct
85 Correct 8 ms 9940 KB Output is correct
86 Correct 9 ms 9844 KB Output is correct
87 Correct 8 ms 9940 KB Output is correct
88 Correct 7 ms 9856 KB Output is correct
89 Correct 7 ms 9940 KB Output is correct
90 Correct 31 ms 13448 KB Output is correct
91 Correct 32 ms 13396 KB Output is correct
92 Correct 30 ms 13392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9636 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 6 ms 9776 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 25 ms 13516 KB Output is correct
25 Correct 22 ms 13560 KB Output is correct
26 Correct 25 ms 13644 KB Output is correct
27 Correct 8 ms 9940 KB Output is correct
28 Correct 9 ms 9940 KB Output is correct
29 Correct 8 ms 9956 KB Output is correct
30 Correct 8 ms 9940 KB Output is correct
31 Correct 8 ms 9904 KB Output is correct
32 Correct 8 ms 9940 KB Output is correct
33 Correct 51 ms 10856 KB Output is correct
34 Correct 55 ms 10836 KB Output is correct
35 Correct 48 ms 10896 KB Output is correct
36 Correct 48 ms 10860 KB Output is correct
37 Correct 49 ms 10892 KB Output is correct
38 Correct 48 ms 10864 KB Output is correct
39 Correct 28 ms 14036 KB Output is correct
40 Correct 29 ms 14036 KB Output is correct
41 Correct 28 ms 13952 KB Output is correct
42 Correct 5 ms 9616 KB Output is correct
43 Correct 6 ms 9684 KB Output is correct
44 Correct 5 ms 9684 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 6 ms 9684 KB Output is correct
48 Correct 5 ms 9720 KB Output is correct
49 Correct 6 ms 9684 KB Output is correct
50 Correct 7 ms 9724 KB Output is correct
51 Correct 5 ms 9720 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 6 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9744 KB Output is correct
56 Correct 5 ms 9684 KB Output is correct
57 Correct 5 ms 9684 KB Output is correct
58 Correct 6 ms 9684 KB Output is correct
59 Correct 7 ms 9684 KB Output is correct
60 Correct 6 ms 9636 KB Output is correct
61 Correct 5 ms 9684 KB Output is correct
62 Correct 6 ms 9684 KB Output is correct
63 Correct 6 ms 9724 KB Output is correct
64 Correct 5 ms 9684 KB Output is correct
65 Correct 5 ms 9684 KB Output is correct
66 Correct 5 ms 9684 KB Output is correct
67 Correct 5 ms 9728 KB Output is correct
68 Correct 5 ms 9684 KB Output is correct
69 Correct 6 ms 9684 KB Output is correct
70 Correct 5 ms 9684 KB Output is correct
71 Correct 5 ms 9684 KB Output is correct
72 Correct 6 ms 9684 KB Output is correct
73 Correct 8 ms 9684 KB Output is correct
74 Correct 6 ms 9684 KB Output is correct
75 Correct 6 ms 9684 KB Output is correct
76 Correct 6 ms 9684 KB Output is correct
77 Correct 6 ms 9696 KB Output is correct
78 Correct 5 ms 9772 KB Output is correct
79 Correct 5 ms 9684 KB Output is correct
80 Correct 6 ms 9728 KB Output is correct
81 Correct 6 ms 9616 KB Output is correct
82 Correct 6 ms 9684 KB Output is correct
83 Correct 5 ms 9684 KB Output is correct
84 Correct 7 ms 9684 KB Output is correct
85 Correct 6 ms 9812 KB Output is correct
86 Correct 6 ms 9812 KB Output is correct
87 Correct 7 ms 9812 KB Output is correct
88 Correct 7 ms 9824 KB Output is correct
89 Correct 7 ms 9812 KB Output is correct
90 Correct 6 ms 9812 KB Output is correct
91 Correct 24 ms 12372 KB Output is correct
92 Correct 21 ms 12764 KB Output is correct
93 Correct 27 ms 13140 KB Output is correct
94 Correct 7 ms 9668 KB Output is correct
95 Correct 7 ms 9736 KB Output is correct
96 Correct 7 ms 9684 KB Output is correct
97 Correct 7 ms 9684 KB Output is correct
98 Correct 7 ms 9684 KB Output is correct
99 Correct 7 ms 9836 KB Output is correct
100 Correct 8 ms 9940 KB Output is correct
101 Correct 9 ms 9844 KB Output is correct
102 Correct 8 ms 9940 KB Output is correct
103 Correct 7 ms 9856 KB Output is correct
104 Correct 7 ms 9940 KB Output is correct
105 Correct 31 ms 13448 KB Output is correct
106 Correct 32 ms 13396 KB Output is correct
107 Correct 30 ms 13392 KB Output is correct
108 Correct 7 ms 9940 KB Output is correct
109 Correct 174 ms 9916 KB Output is correct
110 Correct 90 ms 9864 KB Output is correct
111 Correct 70 ms 9884 KB Output is correct
112 Correct 81 ms 9912 KB Output is correct
113 Correct 53 ms 9900 KB Output is correct
114 Correct 29 ms 11152 KB Output is correct
115 Correct 18 ms 10772 KB Output is correct
116 Correct 34 ms 11132 KB Output is correct
117 Correct 26 ms 10964 KB Output is correct
118 Correct 20 ms 11024 KB Output is correct
119 Correct 39 ms 10760 KB Output is correct
120 Correct 23 ms 12244 KB Output is correct
121 Correct 32 ms 10336 KB Output is correct
122 Correct 25 ms 12312 KB Output is correct
123 Correct 16 ms 10196 KB Output is correct
124 Correct 30 ms 12820 KB Output is correct
125 Correct 15 ms 10440 KB Output is correct
126 Correct 11 ms 10452 KB Output is correct
127 Correct 15 ms 10708 KB Output is correct
128 Correct 11 ms 10452 KB Output is correct
129 Correct 11 ms 10444 KB Output is correct
130 Correct 9 ms 9940 KB Output is correct
131 Correct 237 ms 9972 KB Output is correct
132 Correct 170 ms 9956 KB Output is correct
133 Correct 137 ms 9980 KB Output is correct
134 Correct 116 ms 9980 KB Output is correct
135 Correct 109 ms 9996 KB Output is correct
136 Correct 58 ms 11380 KB Output is correct
137 Correct 57 ms 11352 KB Output is correct
138 Correct 61 ms 11348 KB Output is correct
139 Correct 65 ms 11380 KB Output is correct
140 Correct 62 ms 11348 KB Output is correct
141 Correct 60 ms 11328 KB Output is correct
142 Correct 34 ms 13796 KB Output is correct
143 Correct 48 ms 10580 KB Output is correct
144 Correct 40 ms 13856 KB Output is correct
145 Correct 49 ms 10696 KB Output is correct
146 Correct 48 ms 13760 KB Output is correct
147 Correct 54 ms 10704 KB Output is correct
148 Correct 15 ms 10932 KB Output is correct
149 Correct 15 ms 10844 KB Output is correct
150 Correct 14 ms 10888 KB Output is correct
151 Correct 15 ms 10848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9636 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 6 ms 9776 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 25 ms 13516 KB Output is correct
25 Correct 22 ms 13560 KB Output is correct
26 Correct 25 ms 13644 KB Output is correct
27 Correct 8 ms 9940 KB Output is correct
28 Correct 9 ms 9940 KB Output is correct
29 Correct 8 ms 9956 KB Output is correct
30 Correct 8 ms 9940 KB Output is correct
31 Correct 8 ms 9904 KB Output is correct
32 Correct 8 ms 9940 KB Output is correct
33 Correct 51 ms 10856 KB Output is correct
34 Correct 55 ms 10836 KB Output is correct
35 Correct 48 ms 10896 KB Output is correct
36 Correct 48 ms 10860 KB Output is correct
37 Correct 49 ms 10892 KB Output is correct
38 Correct 48 ms 10864 KB Output is correct
39 Correct 28 ms 14036 KB Output is correct
40 Correct 29 ms 14036 KB Output is correct
41 Correct 28 ms 13952 KB Output is correct
42 Correct 16 ms 10756 KB Output is correct
43 Correct 15 ms 10324 KB Output is correct
44 Correct 20 ms 10964 KB Output is correct
45 Correct 13 ms 10480 KB Output is correct
46 Correct 12 ms 10452 KB Output is correct
47 Correct 17 ms 10880 KB Output is correct
48 Execution timed out 1584 ms 19528 KB Time limit exceeded
49 Halted 0 ms 0 KB -