結果
問題 | No.1695 Mirror Mirror |
ユーザー | eSeF |
提出日時 | 2021-09-15 16:52:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,433 bytes |
コンパイル時間 | 1,371 ms |
コンパイル使用メモリ | 81,552 KB |
実行使用メモリ | 136,300 KB |
最終ジャッジ日時 | 2024-07-19 09:58:08 |
合計ジャッジ時間 | 9,095 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 35 ms
54,220 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 | 34 ms
55,100 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 | 39 ms
53,760 KB |
testcase_28 | AC | 42 ms
56,704 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 | 44 ms
66,812 KB |
testcase_51 | AC | 43 ms
65,252 KB |
testcase_52 | AC | 41 ms
63,104 KB |
testcase_53 | AC | 40 ms
57,928 KB |
testcase_54 | AC | 43 ms
57,256 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 | - |
ソースコード
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])