Submission #1016095

#TimeUsernameProblemLanguageResultExecution timeMemory
1016095vjudge1Bajka (COCI20_bajka)C++17
50 / 70
65 ms792 KiB
#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; 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=dp[0][m]; for (int i=1;i<n;i++) ans=min(ans,dp[i][m]); if (ans>=inf) return cout<<-1<<endl, 0; cout<<ans-1<<endl; return 0; }

Compilation message (stderr)

bajka.cpp: In function 'int main()':
bajka.cpp:19:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |   ind[s[i]].push_back(i);
      |           ^
bajka.cpp:23:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |    for (int k:ind[s[i]])
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...