Submission #1011865

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10118652024-07-01 09:57:15DedibeatBajka (COCI20_bajka)C++14
0 / 70
3 ms1116 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n, m;
cin >> n >> m;
string a, b;
cin >> a >> b;
int dp[n+5][m+5];
map<char, vector<int> > mp;
for(int i = 0; i<n; i++) mp[a[i]].push_back(i);
for(int i = 0; i<=m; i++){
for(int j = 0; j<n; j++) dp[i][j] = 1e18;
}
for(int j = 0; j<n; j++) {
if(a[j] == b[0]) dp[0][j] = 0;
}
for(int i = 1; i<m; i++){
for(int j = 0; j<n; j++){
if(a[j] == b[i]) {
// cout << j << endl;
if(j > 0) {
char x = a[j-1];
auto v = mp[x];
for(auto k : v){
int cost = abs((j - 1) - k);
dp[i][j] = min(dp[i-1][k] + cost, dp[i][j]);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...