#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (a); i > (b); --i)
#define TRAV(a,x) for (auto& a: x)
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;
#define pb push_back
const int INF = int(1e9);
vector<pii> interval;
int check(int a, vector<int> b){
for (auto i : b) if (a==i) return 1;
return 0;
}
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
vi window(M,0);
FOR(m,0,M){
FOR(i,0,M){
window[i] += check(C[(m+i)%M], B[m]);
}
}
// interval
for(auto i : window){
if (i==M) interval.pb({0,M-1});
}
FOR(n,M,N){
FOR(i,0,M){
window[i] += (check(C[n], B[(M+n-i)%M]) - check(C[n-M], B[(M+n-i)%M]));
}
for(auto i : window){
if (i==M) interval.pb({n-M,n});
}
}
if (interval[0].first != 0) return -1;
else {
int r = interval[0].second; int ans=1; int b=1;
while(b<sz(interval)){
if ((b+1) < sz(interval) && interval[b+1].first <= r) {
++b;
}
else if (interval[b].first <= (r+1)){
r=interval[b].second; ++ans; ++b;
}
else break;
}
if (r!=(N-1)) return -1;
else return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
320 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Runtime error |
7 ms |
332 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
320 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Runtime error |
7 ms |
332 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
320 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Runtime error |
7 ms |
332 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
320 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Runtime error |
7 ms |
332 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
320 KB |
Output is correct |
15 |
Correct |
6 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
316 KB |
Output is correct |
19 |
Runtime error |
7 ms |
332 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |