#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
const int MAXN = 1e5+7;
int n, m, k;
int color[MAXN];
vector <int> isLiked[MAXN];
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
n = N; m = M; k = K;
for (int i = 0; i < n; i++) color[i] = C[i];
for (int i = 0; i < m; i++) {
for (auto to : B[i]) {
isLiked[to].pb(i);
}
}
int fk = 0;
for (int i = 0; i < k; i++) {
fk = max(fk, sz(isLiked[i]));
}
if (fk < 2) {
int flag = 1;
for (int i = 0; i+m < n; i++) {
if (color[i] != color[i+m]) flag = 0;
}
if (flag) {
if (sz(isLiked[color[0]]) == 0) {
flag = 0;
}
else {
int start = isLiked[color[0]].back();
for (int i = 0; i < m; i++) {
if (sz(isLiked[color[i]]) == 0 || isLiked[color[i]].back() != (start+i)%m) {
flag = 0;
}
}
}
}
if (flag) return (n+m-1)/m;
else return -1;
}
else {
vector <int> pos;
for (int start = 0; start < m; start++) {
int bad = 0;
for (int i = 0; i < n; i++) {
if (binary_search(all(isLiked[color[i]]), (start+i)%m)) {
}
else {
bad++;
}
if (i >= m) {
if (binary_search(all(isLiked[color[i-m]]), (start+i-m)%m)) {
}
else {
bad--;
}
}
if (i >= m-1 && bad == 0) {
pos.pb(i-m+1);
}
}
}
sort(all(pos));
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2668 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |