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, vis(N);
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);
}
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)
vis[pos_ok[i][l]] = 1;
}
}
for (int i = 0; i < N; i++)
if (vis[i]) ok.push_back(i);
ok.push_back(N);
int res = 0, p = 0;
if (!vis[0]) return -1;
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... |