#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 vll vector<ll>
#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 INF = 1e9;
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_map<int,bool>> vv(k);
for(int i = 0;i < m;++i){
for(int j : b[i]){
val[j].pb(i);
vv[j][i] = true;
}
}
for(int j : val[c[n-1]]) {
DP[n-1][j] = 1;
}
for(int i = n-2;i >= 0;--i){
int x = 0;
for(int j : val[c[i+1]]){
int th = (j - 1 + m) % m;
if(vv[c[i]][th]){
x = max(x, DP[i][th] = max(DP[i][th], DP[i+1][j] + 1));
}
}
for(int j : val[c[i]]){
x = max(x, DP[i][j] = max(DP[i][j], 1));
}
if(x >= m){
F[i] = true;
}
}
vll k1(n+7, INF);
ll l = -1;
for (int i = 0; i <= n-m; i ++) {
bool q = F[i];
while (l != -1 && l < i+m-1 && k1[l] == INF) l ++;
if (q) {
if (l == -1) k1[i+m-1] = 1;
else if (k1[l] != INF) k1[i+m-1] = k1[l]+1;
}
l = max(l, (ll)i);
}
if (k1[n-1] == INF) return -1;
return k1[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... |