結果

問題 No.1695 Mirror Mirror
ユーザー eSeFeSeF
提出日時 2021-09-15 16:52:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 86,660 KB
実行使用メモリ 139,604 KB
最終ジャッジ日時 2023-09-26 15:53:30
合計ジャッジ時間 14,062 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 100 ms
71,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 97 ms
71,260 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 98 ms
71,564 KB
testcase_28 AC 101 ms
73,232 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 103 ms
78,044 KB
testcase_51 AC 102 ms
78,848 KB
testcase_52 AC 103 ms
77,512 KB
testcase_53 AC 100 ms
72,952 KB
testcase_54 AC 101 ms
72,920 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def manacher(s):
    i, j = 0, 0
    n = len(s)
    ret = [0]*n
    while i < n:
        while i-j>=0 and i+j<n and s[i-j]==s[i+j]:
            j+=1
        ret[i] = j
        k = 1
        while i-k>=0 and k+ret[i-k]<j:
            ret[i+k]=ret[i-k]
            k+=1
        i+=k
        j-=k
    return ret

def manacher_even(s):
    n = len(s)
    ret = [0]*(n-1)
    ss = ['@']*(2*n)
    for i in range(n):
        ss[2*i] = s[i]
    m = manacher(ss)
    for i in range(n-1):
        ret[i] = m[2*i+1]//2
    return ret

N, M = map(int,input().split())
S = input()
T = input()

if M%2==1:
    print(-1)
    exit(0)
for i in range(M):
    if T[i]!=T[M-1-i]:
        print(-1)
        exit(0)
    

M//=2
T = T[0:M]
print(T)
INF = 1<<30
dp = [INF]*M
bfs = deque()
for i in range(N):
    if i>=M or S[i]!=T[i]:
        break
    dp[i] = 1
    bfs.append(i)

for i in range(N):
    if i>= M or S[N-1-i]!=T[i]:
        break
    if dp[i] == INF:
        bfs.append(i)
    dp[i] = 1

R = manacher_even(T)
G = [[]for i in range(M)]
for i in range(M-1):
    G[i+1].append((i,0))
    if R[i] > 0:
        G[i].append((i+R[i],1))

while len(bfs) > 0:
    v = bfs.popleft()
    for (nx, c) in G[v]:
        if dp[nx] > dp[v] + c:
            dp[nx] = dp[v] + c
            if c == 0:
                bfs.appendleft(nx)
            else:
                bfs.append(nx)

print(-1 if dp[M-1] == INF else dp[M-1])
0