#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, k;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
vector<int> a, c;
vector<vector<int>> b;
n = N;
m = M;
k = K;
c = C;
a = A;
b = B;
assert((int)c.size() == n);
assert((int)a.size() == m);
assert((int)b.size() == m);
for (int i = 0; i < m; i++) {
assert((int)b[i].size() == a[i]);
}
vector<int> f(k, 0);
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
f[it]++;
}
}
vector<int> has(k, -1);
vector<int> need(n, 0);
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
has[it] = i;
}
}
for (int i = 0; i < n; i++) {
if (f[c[i]] == 0) {
return -1;
}
need[i] = has[c[i]];
}
int sol = 0, pos = c[0], cur = 0;
for (int i = 1; i < n; i++) {
bool ok = false;
ok |= (need[i] == (pos + 1) % m);
if (!ok) {
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
cur = 0;
}
cur++;
pos = need[i];
}
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |