結果
問題 | No.874 正規表現間距離 |
ユーザー | nebukuro09 |
提出日時 | 2019-08-31 00:11:59 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 2,881 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 112,656 KB |
実行使用メモリ | 19,680 KB |
最終ジャッジ日時 | 2024-06-22 02:26:44 |
合計ジャッジ時間 | 2,191 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 0 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 8 ms
6,944 KB |
testcase_17 | AC | 8 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 28 ms
11,524 KB |
testcase_26 | AC | 27 ms
10,252 KB |
testcase_27 | AC | 58 ms
19,680 KB |
testcase_28 | AC | 57 ms
16,992 KB |
testcase_29 | AC | 60 ms
18,560 KB |
testcase_30 | AC | 68 ms
19,452 KB |
testcase_31 | AC | 65 ms
17,084 KB |
testcase_32 | AC | 63 ms
17,116 KB |
testcase_33 | AC | 1 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,944 KB |
testcase_36 | AC | 17 ms
6,944 KB |
testcase_37 | AC | 18 ms
6,940 KB |
testcase_38 | AC | 1 ms
6,944 KB |
testcase_39 | AC | 1 ms
6,940 KB |
testcase_40 | AC | 1 ms
6,940 KB |
testcase_41 | AC | 1 ms
6,940 KB |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto S = readln.chomp; auto T = readln.chomp; string s, t; int[] sx, tx; foreach (c; S) { if (c == '?') sx.back = 1; else if (c == '*') sx.back = 2; else s ~= c, sx ~= 0; } foreach (c; T) { if (c == '?') tx.back = 1; else if (c == '*') tx.back = 2; else t ~= c, tx ~= 0; } auto n = s.length.to!int; auto m = t.length.to!int; auto dp = new int[][](n + 1, m + 1); foreach (i; 0..n+1) dp[i][] = 1 << 29; dp[0][0] = 0; foreach (i; 0..n+1) { foreach (j; 0..m+1) { if (i == n && j == m) { continue; } if (i == n) { dp[i][j+1] = min(dp[i][j+1], dp[i][j] + (tx[j] == 0)); continue; } if (j == m) { dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (sx[i] == 0)); continue; } if (sx[i] == 2 && tx[j] == 2) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); dp[i+1][j] = min(dp[i+1][j], dp[i][j]); dp[i][j+1] = min(dp[i][j+1], dp[i][j]); } else if (sx[i] == 2) { dp[i+1][j] = min(dp[i+1][j], dp[i][j]); if (s[i] == t[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); dp[i][j+1] = min(dp[i][j+1], dp[i][j]); } } else if (tx[j] == 2) { dp[i][j+1] = min(dp[i][j+1], dp[i][j]); if (s[i] == t[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); dp[i+1][j] = min(dp[i+1][j], dp[i][j]); } } if (sx[i] == 1 && tx[j] == 1) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); dp[i+1][j] = min(dp[i+1][j], dp[i][j]); dp[i][j+1] = min(dp[i][j+1], dp[i][j]); } else if (sx[i] == 1) { dp[i+1][j] = min(dp[i+1][j], dp[i][j]); if (s[i] == t[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); } } else if (tx[j] == 1) { dp[i][j+1] = min(dp[i][j+1], dp[i][j]); if (s[i] == t[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); } } if (s[i] == t[j]) { dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]); } dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1); dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1); dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1); } } dp[n][m].writeln; }