이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
int sum(int a, int b) {
return a * b;
}
mt19937 rng((long long) (new char));
const int INF = (int) 1e9;
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
vector<int> can(n, 0);
vector<set<int>> match(m);
vector<vector<int>> guys(k);
for (int i = 0; i < m; i++) {
for (auto &j : b[i]) {
match[i].insert(j);
guys[j].push_back(i);
}
}
for (int i = 0; i + m - 1 < n; i++) {
/// can[i] = 1?
int raz = rng() % m;
for (auto &val : guys[c[i + raz]]) {
int x = (val - raz + m) % m;
assert(x >= 0);
bool good = 1;
for (int l = 0; l < m; l++) {
if (!match[(x + l) % m].count(c[i + l])) {
good = 0;
break;
}
}
if (good) {
can[i] = 1;
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;
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;
}
for (int lastend = start - 1; lastend <= i - 1; lastend++) {
dp[i] = min(dp[i], dp[lastend] + 1);
}
}
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... |