This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
vector<vector<int>> pos(K), pos_ok(M);
vector<int> ok;
for (int i = 0; i < M; i++) {
for (int col : B[i])
pos[col].push_back(i);
}
for (int i = 0; i < N; i++) {
if (C[i] >= K || C[i] < 0) continue;
for (int j : pos[C[i]])
pos_ok[((j - i) % M + M) % M].push_back(i);
}
return -1;
for (int i = 0; i < M; i++) {
for (int l = 0, r = M - 1; r < (int) pos_ok[i].size(); l ++, r ++) {
if (pos_ok[i][r] - pos_ok[i][l] + 1 == M)
ok.push_back(pos_ok[i][l]);
}
}
ok.push_back(N);
sort(ok.begin(), ok.end());
ok.erase(unique(ok.begin(), ok.end()), ok.end());
int res = 0, p = 0;
for (int np; p < N; res ++, p = np) {
if (p == (np = *prev(upper_bound(ok.begin(), ok.end(), p + M))))
return -1;
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |