#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);
}
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 + M) % M]--;
}
for(int i=M-1;i<N;i++){
for(auto j : brr[C[i]])stuf[(j - i + M) % M]--;
int rv = i - (M - 1) - 1;
if(rv >= 0){
for(auto j : brr[C[rv]])stuf[(j - rv + M) % M]++;
}
for(int j=0;j<M;j++)if(stuf[j] == 0)ok[i] = 1;
}
for(int i = 0; i < M - 1; i++)dp[i] = 2e9;
for(int i=M - 1;i<N;i++){
dp[i] = 2e9;
//cout << ok[i] << ' ';
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;
}
}
return (dp[N - 1] == 2e9 ? -1 : dp[N - 1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9704 KB |
Output is correct |
5 |
Correct |
8 ms |
9712 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 |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9704 KB |
Output is correct |
12 |
Correct |
6 ms |
9632 KB |
Output is correct |
13 |
Incorrect |
8 ms |
9684 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9704 KB |
Output is correct |
5 |
Correct |
8 ms |
9712 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 |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9704 KB |
Output is correct |
12 |
Correct |
6 ms |
9632 KB |
Output is correct |
13 |
Incorrect |
8 ms |
9684 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9704 KB |
Output is correct |
5 |
Correct |
8 ms |
9712 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 |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9704 KB |
Output is correct |
12 |
Correct |
6 ms |
9632 KB |
Output is correct |
13 |
Incorrect |
8 ms |
9684 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9704 KB |
Output is correct |
5 |
Correct |
8 ms |
9712 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 |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9704 KB |
Output is correct |
12 |
Correct |
6 ms |
9632 KB |
Output is correct |
13 |
Incorrect |
8 ms |
9684 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9704 KB |
Output is correct |
5 |
Correct |
8 ms |
9712 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 |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9704 KB |
Output is correct |
12 |
Correct |
6 ms |
9632 KB |
Output is correct |
13 |
Incorrect |
8 ms |
9684 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |