#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define str string
#define sz(a) (int) a.size()
#define pii pair<int,int>
#define vi vector<int>
#define rall(a) a.rbegin(), a.rend()
#define all(a) a.begin(), a.end()
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define debug(a) cout << #a << " = " << a << endl;
#define fff cout << "----------------------------------------" <<endl;
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
// using namespace __gnu_pbds;
mt19937 rng(47);
int randint(int l, int r){
return uniform_int_distribution<int>(l, r)(rng);
}
int minimumInstructions(int n, int m, int k, vi c, vi a, vector<vi> b) {
vector<unordered_map<int,int>> dp(n);
vector<bool> good(n, false);
vector<vector<int>> pos(k);
vector<unordered_set<int>> ok(k);
for (int i = 0; i < m; i++) {
for (int col : b[i]) {
pos[col].push_back(i);
ok[col].insert(i);
}
}
for (int j : pos[c[n - 1]]) {
dp[n - 1][j] = 1;
}
for (int i = n - 2; i >= 0; i--) {
int best = 0;
for (auto [j, val] : dp[i + 1]) {
int prev = (j - 1 + m) % m;
if (ok[c[i]].count(prev)) {
dp[i][prev] = max(dp[i][prev], val + 1);
best = max(best, dp[i][prev]);
}
}
for (int j : pos[c[i]]) {
dp[i][j] = max(dp[i][j], 1);
best = max(best, dp[i][j]);
}
if (best >= m) good[i] = true;
}
int ans = 0;
int i = 0;
while (i < n) {
bool found = false;
for (int j = i; j < min(n, i + m); j++) {
if (good[j]) {
ans++;
i = j + m;
found = true;
break;
}
}
if (!found) return -1;
}
return 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... |