#include "paint.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> f[100005];
bool poss[100005];
int seg[4*200005];
void update(int i, int l, int r, int x, int val) {
if(l==r) {
seg[i] += val;
return;
}
int m = (l+r)/2;
if(x<=m) update(i*2+1, l, m, x, val);
else update(i*2+2, m+1, r, x, val);
seg[i] = max(seg[i*2+1], seg[i*2+2]);
}
int dp[100005];
int minimumInstructions(int N, int M, int K, std::vector<int> C, vector<int> A, vector<vector<int>> B) {
for(int i=0;i<B.size();i++) {
for(int k:B[i]) f[k].push_back(i);
}
/*for(int i=0;i<M;i++) {
for(int p:f[C[i]]) update(0, 0, (int)1e5, (p-(i%M)+M)%M, 1);
}
if(seg[0]==M) poss[M-1] = 1;
else return -1;
for(int i=M;i<N;i++) {
for(int p:f[C[i-M]]) update(0, 0, (int)1e5, (p-(i%M)+M)%M, -1);
for(int p:f[C[i]]) update(0, 0, (int)1e5, (p-(i%M)+M)%M, 1);
if(seg[0]==M) poss[i] = 1;
}
int last = M-1;
for(int i=0;i<=last;i++) dp[i] = 1;
for(int i=M;i<N;i++) {
if(last<i-M) return -1;
if(!poss[i]) continue;
for(int j=last+1;j<=i;j++) dp[j] = dp[i-M]+1;
last = i;
}
return dp[N-1];*/
for(int i=1;i<N;i++) {
int last = f[C[i-1]][0];
int cur = f[C[i]][0];
if((last+1)%M!=cur) return -1;
}
return (N+M-1)/M;
}
Compilation message
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<B.size();i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |