Submission #806683

#TimeUsernameProblemLanguageResultExecution timeMemory
806683Tunglam07Bajka (COCI20_bajka)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; long long n, m, minn = INT_MAX, pre[301][301]; string s, t; vector<int> ch[27]; long long backtrack(int id, int pos) { if(pre[id][pos]) { return pre[id][pos]; } if(pos == m) { return 0; } long long ans = INT_MAX; for(int i : ch[s[id] - 96]) { if(i < n - 1 && s[i + 1] == t[pos]) { ans = min(ans, backtrack(i + 1, pos + 1) + abs(id - i) + 1); } if(i > 0 && s[i - 1] == t[pos]) { ans = min(ans, backtrack(i - 1, pos + 1) + abs(id - i) + 1); } } val[id][pos] = ans; return ans; } int main() { cin >> n >> m; cin>> s; cin>> t; for(int i = 0; i < n; i++) { ch[s[i] - 96].push_back(i); } for(int c : ch[t[0] - 96]) { minn = min(minn, backtrack(c, 1)); } if(minn < INT_MAX) { cout << minn; return 0; } cout << -1; }

Compilation message (stderr)

bajka.cpp: In function 'long long int backtrack(int, int)':
bajka.cpp:30:2: error: 'val' was not declared in this scope
   30 |  val[id][pos] = ans;
      |  ^~~