이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B) {
vector<int> dp(N+1,INF);
vector<unordered_set<int>> s(M);
for(int i=0;i<M;i++){
for(int j:B[i]){
s[i].insert(j);
}
}
auto check=[&](int st,int now)->int {
for(int i=st;i<st+M;i++){
if(!s[now].count(C[i]))return 0;
now++;
now%=M;
}
return 1;
};
deque<int> d;
d.push_back(0);
dp[0]=0;
for(int i=M;i<=N;i++){
while(d.size()&&d.front()<i-M){
d.pop_front();
}
int flag=0;
for(int j=0;j<M;j++){
flag|=check(i-M,j);
}
if(flag){
dp[i]=dp[d.front()]+1;
}
while(d.size()&&dp[d.back()]>dp[i]){
d.pop_back();
}
d.push_back(i);
}
return (dp[N]==INF?-1:dp[N]);
return 0;
}
# | 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... |