#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int minimumInstructions(int n,int m,int k,vector<int>C,vector<int>A,vector<vector<int>>B){
vector<vector<int>>q(n,vector<int>(m));
vector<vector<bool>>have(n,vector<bool>(m,0));
for(int i=0;i<m;i++){
for(auto x:B[i]){
have[i][x]=true;
}
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<m;j++){
if(have[C[i]][j]==false){
q[i][j]=-1e9;
}
else if(i==n-1||have[C[i]][(j+1)%m]==false){
q[i][j]=1;
}
else{
q[i][j]=q[i+1][(j+1)%m]+1;
}
}
}
vector<int>mn(n+1,1e9);
mn[n]=0;
multiset<int>st;
for(int i=n-m+1;i<=n;i++){
st.insert(mn[i]);
}
for(int i=n-m;i>=0;i--){
bool ok=false;
for(int j=0;j<m;j++){
if(q[i][j]>=m){
ok=true;
break;
}
}
if(ok){
mn[i]=*st.begin()+1;
}
st.erase(st.find(mn[i+m]));
st.insert(mn[i]);
}
if(mn[0]==1e9) return -1;
return mn[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |