結果
問題 | No.874 正規表現間距離 |
ユーザー | mkawa2 |
提出日時 | 2022-03-18 12:22:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 608 ms / 2,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 370 ms |
コンパイル使用メモリ | 81,896 KB |
実行使用メモリ | 110,100 KB |
最終ジャッジ日時 | 2024-10-02 15:17:29 |
合計ジャッジ時間 | 7,641 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,292 KB |
testcase_01 | AC | 39 ms
52,616 KB |
testcase_02 | AC | 39 ms
53,664 KB |
testcase_03 | AC | 38 ms
53,788 KB |
testcase_04 | AC | 39 ms
53,420 KB |
testcase_05 | AC | 38 ms
52,260 KB |
testcase_06 | AC | 38 ms
53,176 KB |
testcase_07 | AC | 40 ms
53,312 KB |
testcase_08 | AC | 39 ms
53,500 KB |
testcase_09 | AC | 39 ms
53,788 KB |
testcase_10 | AC | 39 ms
53,652 KB |
testcase_11 | AC | 38 ms
53,384 KB |
testcase_12 | AC | 39 ms
54,080 KB |
testcase_13 | AC | 38 ms
52,888 KB |
testcase_14 | AC | 38 ms
53,948 KB |
testcase_15 | AC | 38 ms
52,948 KB |
testcase_16 | AC | 129 ms
83,832 KB |
testcase_17 | AC | 133 ms
84,628 KB |
testcase_18 | AC | 39 ms
54,068 KB |
testcase_19 | AC | 38 ms
53,536 KB |
testcase_20 | AC | 38 ms
52,764 KB |
testcase_21 | AC | 41 ms
53,032 KB |
testcase_22 | AC | 41 ms
53,636 KB |
testcase_23 | AC | 41 ms
54,536 KB |
testcase_24 | AC | 39 ms
52,884 KB |
testcase_25 | AC | 287 ms
108,440 KB |
testcase_26 | AC | 281 ms
108,200 KB |
testcase_27 | AC | 521 ms
108,280 KB |
testcase_28 | AC | 607 ms
110,100 KB |
testcase_29 | AC | 513 ms
108,176 KB |
testcase_30 | AC | 538 ms
108,348 KB |
testcase_31 | AC | 608 ms
109,580 KB |
testcase_32 | AC | 598 ms
109,468 KB |
testcase_33 | AC | 62 ms
68,760 KB |
testcase_34 | AC | 38 ms
53,372 KB |
testcase_35 | AC | 88 ms
75,936 KB |
testcase_36 | AC | 275 ms
85,464 KB |
testcase_37 | AC | 275 ms
85,544 KB |
testcase_38 | AC | 38 ms
53,096 KB |
testcase_39 | AC | 38 ms
52,812 KB |
testcase_40 | AC | 39 ms
54,088 KB |
testcase_41 | AC | 38 ms
53,108 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])