#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> F(n);
vector<vi> val(k);
vector<unordered_set<int>> ok(k);
for(int i = 0;i < m;++i){
for(int j : b[i]){
val[j].pb(i);
ok[j].insert(i);
}
}
for(int j : val[c[n-1]]) {
DP[n-1][j] = n-1;
}
for(int i = n-2;i >= 0;--i){
int best = i;
for(auto [j, reach] : DP[i+1]){
int th = (j - 1 + m) % m;
if(ok[c[i]].count(th)){
DP[i][th] = max(DP[i][th], reach);
best = max(best, DP[i][th]);
}
}
for(int j : val[c[i]]){
DP[i][j] = max(DP[i][j], i);
best = max(best, DP[i][j]);
}
if(best - i + 1 >= m)
F[i] = true;
}
const int INF = 1e9;
vector<int> g(n, INF);
for(int i = 0;i + m - 1 < n;i++){
if(F[i]){
int L = (i == 0 ? 0 : g[i-1]);
g[i+m-1] = min(g[i+m-1], L + 1);
}
if(i > 0)
g[i] = min(g[i], g[i-1]);
}
if(g[n-1] >= INF) return -1;
return g[n-1];
}
| # | 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... |