/*#pragma GCC optimize("O3")
#pragma GCC optimization("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/
#include <bits/stdc++.h>
#include "paint.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
const ll INF = 1e18+7;
const int lg = 20;
//const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
mt19937 rng(1488);
ll randll(ll l, ll r) {
return uniform_int_distribution<ll>(l, r)(rng);
}
int minimumInstructions(int n, int m, int k, vi c, vi a, vector<vi> b) {
vvll col(k+7);
for (int i = 0; i < m; i ++) {
for (int j : b[i]) {
col[j].pb(i);
}
}
vll dp;
vbool us(n, 0);
for (int i = n-1; i >= 0; i --) {
vll dp1(col[c[i]].size());
ll l = 0, l1 = 0;
for (int j : col[c[i]]) {
if (i == n-1) dp1[l1] = i;
else {
if (j+1 == m) l = 0;
while (l < col[c[i+1]].size() && col[c[i+1]][l] < (j+1)%m) l ++;
if (l == col[c[i+1]].size() || col[c[i+1]][l] != (j+1)%m) dp1[l1] = i;
else dp1[l1] = dp[l];
}
l1 ++;
}
dp = dp1;
for (int j = 0; j < dp.size(); j ++) {
//cout << dp[j] << ' ';
if (dp[j]-i >= m-1) {
us[i] = 1;
break;
}
}
//cout << endl;
}
vll k1(n+7, INF);
ll l = -1;
for (int i = 0; i <= n-m; i ++) {
bool q = us[i];
//cout << endl;
//cout << q << endl;
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];
}
/*int main(){
speed;
srand(time(0));
cout << minimumInstructions(8, 3, 5, {3, 3, 1, 3, 4, 4, 2, 2}, {3, 2, 2}, {{0, 1, 2}, {2, 3}, {3,4}}) << endl;
}*/
| # | 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... |