# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
472622 | kungfulon | Bajka (COCI20_bajka) | C++17 | 58 ms | 660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
int main(int argc,const char** argv){
int n,m,ans = 1e9;
cin >> n >> m;
string s,t;
cin >> s >> t;
vector<vector<int>> dp(m,vector<int>(n,1e9));
for(int i = 0;i < m;i++){
vector<int> f; // save pos
for(int j = 0;j < n;j++) if(s[j] == t[i]) f.push_back(j);
for(int pos : f){
if(!i) dp[i][pos] = 0;
else{
if(pos && s[pos - 1] == t[i - 1]){
dp[i][pos] = min(dp[i][pos],dp[i - 1][pos - 1] + 1);
}
if(pos < n - 1 && s[pos + 1] == t[i - 1]){
dp[i][pos] = min(dp[i][pos],dp[i - 1][pos + 1] + 1);
}
}
}
for(int l = 0;l < f.size();l++){
for(int r = 0;r < f.size();r++){
dp[i][f[l]] = min(dp[i][f[l]], abs(f[l] - f[r]) + dp[i][f[r]]);
}
if(i == m - 1){
ans = min(ans,dp[i][f[l]]);
}
}
}
cout << (ans < 1e9 ? ans : -1);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |