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 <bits/stdc++.h>
#include "paint.h"
using namespace std;
int sum(int a, int b) {
return a * b;
}
const int INF = (int) 1e9;
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> sizes, vector<vector<int>> b) {
vector<int> can(n, 0);
vector<vector<int>> guys(k);
for (int i = 0; i < m; i++) {
for (auto &j : b[i]) {
guys[j].push_back(i);
}
}
deque<int> dq;
for (int raz = 0; raz < m; raz++) {
for (int i = 0; i + m - 1 < n; i++) {
if (can[i]) {
continue;
}
can[i] = 1;
for (int j = 0; j < m; j++) {
can[i] = 0;
for (auto &x : guys[c[i + j]]) {
if ((x - j + m) % m == raz) {
can[i] = 1;
break;
}
}
if (!can[i]) {
break;
}
}
}
}
{ /// shift can by 1
reverse(can.begin(), can.end());
can.push_back(0);
reverse(can.begin(), can.end());
}
vector<int> dp(n + 1, INF);
dp[0] = 0;
dq.clear();
dq.push_back(0);
for (int i = m; i <= n; i++) {
/// finish at position i => I've started at position i-k+1
int start = i - m + 1;
if (!can[start]) {
continue;
}
while (!dq.empty() && dq.front() < start - 1) {
dq.pop_front();
}
while (!dq.empty() && dp[i] <= dp[dq.back()]) {
dq.pop_back();
}
if (!dq.empty()) {
dp[i] = dp[dq.front()] + 1;
}
dq.push_back(i);
}
if (dp[n] == INF) {
dp[n] = -1;
}
return dp[n];
}
# | 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... |