# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016098 | 2024-07-07T11:46:30 Z | vjudge1 | Bajka (COCI20_bajka) | C++17 | 56 ms | 788 KB |
#include <bits/stdc++.h> using namespace std; const int inf = 1e6; int main() { int n,m; cin>>n>>m; string s,t; cin>>s>>t; int dp[n][m+1]; for (int i=0;i<n;i++) for (int j=0;j<=m;j++) dp[i][j]=inf*(j>0); vector<int> ind[256]; for (int i=0;i<n;i++) ind[s[i]].push_back(i); for (int j=1;j<=m;j++) for (int i=0;i<n;i++) { for (int k:ind[s[i]]) { if (k && s[k-1]==t[m-j]) dp[i][j]=min(dp[i][j],dp[k-1][j-1]+1+abs(i-k)); if (k<n-1 && s[k+1]==t[m-j]) dp[i][j]=min(dp[i][j],dp[k+1][j-1]+1+abs(i-k)); } } int ans=inf; for (int i=0;i<n;i++) if (s[i]==t[0]) ans=min(ans,dp[i][m-1]); if (ans>=inf) ans=-1; cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 440 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 604 KB | Output is correct |
2 | Correct | 11 ms | 788 KB | Output is correct |
3 | Correct | 4 ms | 604 KB | Output is correct |
4 | Correct | 5 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 13 ms | 604 KB | Output is correct |
8 | Correct | 28 ms | 604 KB | Output is correct |
9 | Correct | 56 ms | 600 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 12 ms | 604 KB | Output is correct |