# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314861 | 2020-10-21T14:18:46 Z | model_code | Bajka (COCI20_bajka) | C++17 | 71 ms | 768 KB |
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int MAXN = 305; const int inf = 1000000; int n, m, dp[MAXN][MAXN]; char s[MAXN], p[MAXN]; int rek(int a, int b) { if (b == m) return 0; if (dp[a][b] != -1) return dp[a][b]; int ret = inf; REP(i, n) { if (s[i] == s[a]) { FOR(j, -1, 2) { if (!j || i + j < 0 || i + j >= n) continue; if (s[i + j] != p[b]) continue; ret = min(ret, rek(i + j, b + 1) + abs(i - a) + 1); } } } return dp[a][b] = ret; } int main() { scanf("%d %d",&n,&m); scanf("%s",s); scanf("%s",p); memset(dp, -1, sizeof dp); int sol = inf; REP(i, n) if (s[i] == p[0]) sol = min(sol, rek(i, 1)); if (sol >= inf) sol = -1; printf("%d\n",sol); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 640 KB | Output is correct |
2 | Correct | 1 ms | 640 KB | Output is correct |
3 | Correct | 1 ms | 640 KB | Output is correct |
4 | Correct | 1 ms | 640 KB | Output is correct |
5 | Correct | 1 ms | 640 KB | Output is correct |
6 | Correct | 1 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 768 KB | Output is correct |
3 | Correct | 1 ms | 640 KB | Output is correct |
4 | Correct | 1 ms | 640 KB | Output is correct |
5 | Correct | 1 ms | 640 KB | Output is correct |
6 | Correct | 1 ms | 640 KB | Output is correct |
7 | Correct | 11 ms | 640 KB | Output is correct |
8 | Correct | 71 ms | 640 KB | Output is correct |
9 | Correct | 67 ms | 640 KB | Output is correct |
10 | Correct | 1 ms | 640 KB | Output is correct |
11 | Correct | 7 ms | 640 KB | Output is correct |