結果

問題 No.874 正規表現間距離
ユーザー vwxyzvwxyz
提出日時 2024-04-19 13:38:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 1,714 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 108,800 KB
最終ジャッジ日時 2024-04-19 13:38:25
合計ジャッジ時間 6,294 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 44 ms
52,352 KB
testcase_02 AC 43 ms
52,608 KB
testcase_03 AC 44 ms
52,352 KB
testcase_04 AC 44 ms
52,352 KB
testcase_05 AC 44 ms
52,480 KB
testcase_06 AC 38 ms
52,736 KB
testcase_07 AC 43 ms
52,352 KB
testcase_08 AC 43 ms
52,480 KB
testcase_09 AC 44 ms
52,480 KB
testcase_10 AC 43 ms
52,608 KB
testcase_11 AC 37 ms
52,480 KB
testcase_12 AC 38 ms
52,224 KB
testcase_13 AC 38 ms
52,480 KB
testcase_14 AC 42 ms
52,480 KB
testcase_15 AC 43 ms
52,480 KB
testcase_16 AC 116 ms
78,892 KB
testcase_17 AC 132 ms
78,992 KB
testcase_18 AC 45 ms
52,736 KB
testcase_19 AC 44 ms
52,608 KB
testcase_20 AC 40 ms
52,096 KB
testcase_21 AC 46 ms
53,120 KB
testcase_22 AC 46 ms
53,248 KB
testcase_23 AC 44 ms
53,120 KB
testcase_24 AC 40 ms
52,608 KB
testcase_25 AC 232 ms
87,424 KB
testcase_26 AC 212 ms
87,552 KB
testcase_27 AC 332 ms
108,160 KB
testcase_28 AC 431 ms
100,948 KB
testcase_29 AC 290 ms
108,160 KB
testcase_30 AC 326 ms
108,800 KB
testcase_31 AC 476 ms
104,860 KB
testcase_32 AC 456 ms
105,352 KB
testcase_33 AC 75 ms
68,096 KB
testcase_34 AC 45 ms
52,608 KB
testcase_35 AC 88 ms
72,704 KB
testcase_36 AC 248 ms
84,948 KB
testcase_37 AC 229 ms
84,572 KB
testcase_38 AC 44 ms
52,480 KB
testcase_39 AC 44 ms
52,480 KB
testcase_40 AC 41 ms
52,096 KB
testcase_41 AC 42 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

A=input()
B=input()
boundA=[0]
boundB=[0]
for i in range(1,len(A)):
    if not A[i] in "*?":
        boundA.append(i)
boundA.append(len(A))
for i in range(1,len(B)):
    if not B[i] in "*?":
        boundB.append(i)
boundB.append(len(B))
A=[A[i:j] for i,j in zip(boundA,boundA[1:])]
B=[B[i:j] for i,j in zip(boundB,boundB[1:])]
leA=len(A)
leB=len(B)
inf=1<<30
dp=[[inf]*(leB+1) for a in range(leA+1)]
dp[0][0]=0
for i in range(leA+1):
    for j in range(leB+1):
        if i:
            dp[i][j]=min(dp[i][j],dp[i-1][j]+1)
            if len(A[i-1])==2 and A[i-1][1] in "?*":
                dp[i][j]=min(dp[i][j],dp[i-1][j])
        if j:
            dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
            if len(B[j-1])==2 and B[j-1][1] in "?*":
                dp[i][j]=min(dp[i][j],dp[i][j-1])
        if i and j:
            dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1)
            if A[i-1]==B[j-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j-1])
            if len(A[i-1])==2 and A[i-1][1]=="?" and A[i-1][0]==B[j-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j-1])
            if len(B[j-1])==2 and B[j-1][1]=="?" and B[j-1][0]==A[i-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j-1])

            if len(A[i-1])==2 and A[i-1][1]=="*" and A[i-1][0]==B[j-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j-1])
            if len(B[j-1])==2 and B[j-1][1]=="*" and B[j-1][0]==A[i-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j-1])

            if len(A[i-1])==2 and A[i-1][1]=="*" and A[i-1][0]==B[j-1]:
                dp[i][j]=min(dp[i][j],dp[i][j-1])
            if len(B[j-1])==2 and B[j-1][1]=="*" and B[j-1][0]==A[i-1]:
                dp[i][j]=min(dp[i][j],dp[i-1][j])
ans=dp[leA][leB]
print(ans)
0