結果

問題 No.874 正規表現間距離
ユーザー vwxyzvwxyz
提出日時 2024-04-19 13:38:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,714 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-19 13:38:12
合計ジャッジ時間 8,677 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
16,640 KB
testcase_01 AC 28 ms
11,008 KB
testcase_02 AC 28 ms
11,136 KB
testcase_03 AC 27 ms
11,008 KB
testcase_04 AC 26 ms
11,008 KB
testcase_05 AC 26 ms
11,136 KB
testcase_06 AC 26 ms
11,008 KB
testcase_07 AC 26 ms
11,136 KB
testcase_08 AC 26 ms
11,136 KB
testcase_09 AC 27 ms
11,136 KB
testcase_10 AC 25 ms
11,136 KB
testcase_11 AC 25 ms
11,136 KB
testcase_12 AC 25 ms
11,136 KB
testcase_13 AC 25 ms
11,136 KB
testcase_14 AC 25 ms
11,136 KB
testcase_15 AC 25 ms
11,136 KB
testcase_16 AC 1,837 ms
13,568 KB
testcase_17 TLE -
testcase_18 AC 27 ms
11,136 KB
testcase_19 AC 28 ms
11,008 KB
testcase_20 AC 27 ms
11,008 KB
testcase_21 AC 25 ms
11,136 KB
testcase_22 AC 27 ms
11,008 KB
testcase_23 AC 26 ms
11,136 KB
testcase_24 AC 28 ms
11,008 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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