Submission #482402

#TimeUsernameProblemLanguageResultExecution timeMemory
482402rainboyBajka (COCI20_bajka)C11
70 / 70
1 ms332 KiB
#include <stdio.h> #define N 300 #define M 300 #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } int main() { static char aa[N + 1], bb[M + 1]; static int dp[N], dq[N]; int n, m, i, j, ans; scanf("%d%d%s%s", &n, &m, aa, bb); for (j = 0; j < m; j++) { if (j > 0) { int p; for (i = 0, p = -1; i < n; i++) if (aa[i] == bb[j - 1]) { if (p != -1) dp[i] = min(dp[i], dp[p] + i - p); p = i; } for (i = n - 1, p = -1; i >= 0; i--) if (aa[i] == bb[j - 1]) { if (p != -1) dp[i] = min(dp[i], dp[p] + p - i); p = i; } for (i = 0; i < n; i++) { dq[i] = min(i == 0 ? INF : dp[i - 1], i + 1 == n ? INF : dp[i + 1]); if (dq[i] != INF) dq[i]++; } } for (i = 0; i < n; i++) dp[i] = aa[i] == bb[j] ? dq[i] : INF; } ans = INF; for (i = 0; i < n; i++) ans = min(ans, dp[i]); if (ans == INF) ans = -1; printf("%d\n", ans); return 0; }

Compilation message (stderr)

bajka.c: In function 'main':
bajka.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d%d%s%s", &n, &m, aa, bb);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...