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 <vector>
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int INF = 1e5+1;
int minimumInstructions(int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B)
{
n = N; m = M; k = K;
vector<int> color(k, -1);
for (int i=0; i<m; i++) {if (A[i] > 0) color[B[i][0]] = i;}
vector<int> cHat(n);
for (int i=0; i<n; i++) {cHat[i] = color[C[i]]; if (cHat[i] == -1) {return -1;}}
vector<int> right(n);
for (int i=n-1; i>=0; i--)
{
if (i == n-1 || cHat[i+1] != (cHat[i]+1)%m) right[i] = i;
else right[i] = right[i+1];
}
vector<bool> p(n);
for (int i=0; i<n; i++)
{
p[i] = (right[i] - i + 1 >= m);
}
//for (auto &u: B) {for (auto &v: u) {cout<<v<<" ";} cout<<'\n';}
//for (auto u: p) {cout<<u<<" ";} cout<<'\n';
vector<int> left(n);
if (p[0]) left[0] = 0;
else left[0] = -INF;
for (int i=1; i<n; i++)
{
if (p[i]) left[i] = i;
else left[i] = left[i-1];
}
//for (auto u: left) {cout<<u<<" ";} cout<<"\n";
vector<int> g(n);
for (int i=n-1; i>=0; i--)
{
//cout<<left[i]+m-1<<"\n";
if (i - left[i] >= m) {g[i] = INF;}
else if (left[i] != -INF && left[i]+m >= n) {g[i] = 1;}
else if (left[i] != -INF && left[i]+m < n) {g[i] = 1 + g[left[i]+m];}
}
//for (auto u: g) {cout<<u<<" ";} cout<<"\n";
return ((g[0] >= INF) ? -1 : g[0]);
}
# | 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... |