This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
//#include "paint.h"
#pragma GCC optimize("O2")
#define deb(x) cout << #x << " = " << x <<endl
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int minimumInstructions(int n,int m,int k,vector<int> c,vector<int> a,vector<vector<int>> b){
vector<int> mp(k,-1);
//mp[i] = position of constructor who like the i th color
for(int i=0;i<m;i++)
if(a[i]>0)
for(auto x:b[i])
mp[x]=i;
int ans=0,cur=-1;
//cur moves in constructors array
for(int i=0;i<n;i++){
if(mp[c[i]]==-1)
return -1;
if(cur==-1)
ans++,cur=mp[c[i]];
else{
if(m==1){
ans++;
continue;
}
cur=(cur+1)%m;
if(a[cur]>0 && b[cur][0]==c[i])
continue;
ans++;
cur=mp[c[i]];
}
}
return ans;
}
/*
int main(){
}
*/
# | 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... |