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;
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], can[MAXN], L[MAXN];
pii last[2][MAXN];
vector <int> isLikedBy[MAXN];
int g(int i) {
if (i >= n) return 0;
else if (i - L[i] >= m) return 1e9;
return 1+g(L[i]+m);
}
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]) {
isLikedBy[to].pb(i);
}
}
for (int i = n-1; i >= 0; i--) {
int type = (i & 1 ? 1 : 0);
for (int j = sz(isLikedBy[color[i]])-1; j >= 0; j--) {
auto worker = isLikedBy[color[i]][j];
if (i == n-1) {
last[type][worker] = mp(i, i);
}
else {
if (last[type^1][(worker+1)%m].first != i+1) {
last[type][worker] = mp(i, i);
}
else {
last[type][worker] = mp(i, last[type^1][(worker+1)%m].second);
}
}
}
for (auto worker : isLikedBy[color[i]]) {
if (last[type][worker].second-i >= m-1) {
can[i] = 1;
}
}
}
int prev = -1e9;
for (int i = 0; i < n; i++) {
if (can[i]) prev = i;
L[i] = prev;
}
auto ans = g(0);
return (ans >= 1e8 ? -1 : ans);
}
# | 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... |