結果
問題 | No.874 正規表現間距離 |
ユーザー | mkawa2 |
提出日時 | 2022-03-18 12:22:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 567 ms / 2,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 110,360 KB |
最終ジャッジ日時 | 2024-04-10 13:14:23 |
合計ジャッジ時間 | 7,102 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,344 KB |
testcase_01 | AC | 36 ms
53,944 KB |
testcase_02 | AC | 35 ms
53,208 KB |
testcase_03 | AC | 35 ms
53,400 KB |
testcase_04 | AC | 34 ms
52,892 KB |
testcase_05 | AC | 33 ms
52,820 KB |
testcase_06 | AC | 35 ms
53,856 KB |
testcase_07 | AC | 35 ms
52,684 KB |
testcase_08 | AC | 35 ms
52,996 KB |
testcase_09 | AC | 36 ms
54,320 KB |
testcase_10 | AC | 34 ms
52,748 KB |
testcase_11 | AC | 35 ms
52,872 KB |
testcase_12 | AC | 36 ms
52,600 KB |
testcase_13 | AC | 37 ms
53,196 KB |
testcase_14 | AC | 35 ms
52,944 KB |
testcase_15 | AC | 35 ms
53,540 KB |
testcase_16 | AC | 118 ms
84,264 KB |
testcase_17 | AC | 122 ms
84,164 KB |
testcase_18 | AC | 35 ms
53,436 KB |
testcase_19 | AC | 36 ms
53,876 KB |
testcase_20 | AC | 35 ms
53,408 KB |
testcase_21 | AC | 35 ms
53,504 KB |
testcase_22 | AC | 37 ms
54,320 KB |
testcase_23 | AC | 37 ms
53,236 KB |
testcase_24 | AC | 34 ms
53,428 KB |
testcase_25 | AC | 268 ms
108,224 KB |
testcase_26 | AC | 262 ms
108,364 KB |
testcase_27 | AC | 480 ms
108,384 KB |
testcase_28 | AC | 545 ms
110,360 KB |
testcase_29 | AC | 482 ms
108,396 KB |
testcase_30 | AC | 491 ms
108,540 KB |
testcase_31 | AC | 567 ms
109,836 KB |
testcase_32 | AC | 548 ms
109,596 KB |
testcase_33 | AC | 56 ms
68,496 KB |
testcase_34 | AC | 36 ms
54,516 KB |
testcase_35 | AC | 82 ms
76,424 KB |
testcase_36 | AC | 261 ms
85,188 KB |
testcase_37 | AC | 247 ms
85,672 KB |
testcase_38 | AC | 35 ms
52,532 KB |
testcase_39 | AC | 34 ms
53,008 KB |
testcase_40 | AC | 34 ms
53,412 KB |
testcase_41 | AC | 35 ms
52,904 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = (1 << 63)-1 inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 s = SI() t = SI() n = len(s) m = len(t) def chmin(i, j, val): if i > n or j > m: return if val < dp[i][j]: dp[i][j] = val dp = [[inf]*(m+1) for _ in range(n+1)] dp[0][0] = 0 for i in range(n+1): if i < n and not s[i].islower(): continue for j in range(m+1): if j < m and not t[j].islower(): continue pre = dp[i][j] di, cost = 1, 1 if i+1 < n and not s[i+1].islower(): di, cost = 2, 0 chmin(i+di, j, pre+cost) dj, cost = 1, 1 if j+1 < m and not t[j+1].islower(): dj, cost = 2, 0 chmin(i, j+dj, pre+cost) cost = 1 if i < n and j < m and s[i] == t[j]: cost = 0 if i+1 < n and s[i+1] == "*": chmin(i, j+dj, pre) if j+1 < m and t[j+1] == "*": chmin(i+di, j, pre) chmin(i+di, j+dj, pre+cost) print(dp[n][m])