이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 2e4+9,MX = 1e9+9;
int n,m,k;
int a[inf];
//vector<int> Cont[inf];
int LCS[inf][2009],dp[inf];
bool valid[inf];
unordered_map<int,int> mp[2009];
bool like(int i,int j){
return mp[j][ a[i] ];
/* int idx = lower_bound(Cont[j].begin(),Cont[j].end(),a[i]) - Cont[j].begin();
if(idx < Cont[j].size() && Cont[j][idx] == a[i])
return 1;
return 0;*/
}
int minimumInstructions(int N, int M, int K, vector<int> C,
vector<int> A,vector<vector<int>> B) {
n = N, m = M,k = K;
for(int i=1;i<=n;i++)
a[i] = C[i-1]+1;
for(int i=1;i<=m;i++){
for(auto o:B[i-1])
/*Cont[i].push_back(o+1),*/mp[i][o+1] = 1;
// sort(Cont[i].begin(),Cont[i].end());
}
for(int i=n;i>=1;i--){
for(int j=m;j>=1;j--){
if(like(i,j))
LCS[i][j] = LCS[i+1][j+1] + 1;
else
LCS[i][j] = 0;
}
}
for(int y=1;y <= n-m+1;y++){
for(int x = 1;x <= m;x++){
int len1 = m-x+1,i1 = y,j1 = x,tmp1;
tmp1 = LCS[i1][j1];
int len2 = x-1,i2 = y+len1,j2 = 1,tmp2 = 0;
if(len2)
tmp2 = LCS[i2][j2];
valid[y] |= (tmp1 >= len1 && tmp2 >= len2);
}
}
for(int i=1;i<=n;i++)
dp[i] = MX;
dp[n-m+1] = (valid[n-m+1]?1:MX);
for(int i=n-m;i>=1;i--)
for(int j=i+1;j<=i+m && valid[i];j++)
dp[i] = min(dp[i],dp[j] + 1);
return ( (dp[1] == MX)?-1:dp[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... |