結果

問題 No.1192 半部分列
ユーザー definedefine
提出日時 2020-08-05 14:56:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,033 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 11,860 KB
実行使用メモリ 85,232 KB
最終ジャッジ日時 2023-10-17 00:55:59
合計ジャッジ時間 13,267 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,256 ms
80,324 KB
testcase_01 AC 1,241 ms
80,324 KB
testcase_02 AC 1,258 ms
80,324 KB
testcase_03 AC 1,257 ms
80,324 KB
testcase_04 AC 1,258 ms
80,324 KB
testcase_05 AC 1,269 ms
80,324 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy
S=input()
T=input()
nexS=[[0] * 26 for i in range(100005)]
nexT=copy.deepcopy(nexS)

for i in range(26):
    nexS[len(S)][i]=len(S)
    nexT[len(T)][i]=len(T)
for i in range(len(S)-1,-1,-1):
    for j in range(26):
        nexS[i][j]=nexS[i+1][j]
    nexS[i][ord(S[i])-0x61]=i
for i in range(len(T)-1,-1,-1):
    for j in range(26):
        nexT[i][j]=nexT[i+1][j]
    nexT[i][ord(T[i])-0x61]=i

inc=[0 for i in range(100005)]
now=len(T)
inc[len(S)]=now
for i in range(len(S)-1,-1,-1):
    now=max(-1,now-1)
    while now>=0 and T[now]!=S[i]:
        now-=1
    inc[i]=now
if inc[0]!=-1:
    print(-1)
    exit(0)

Ans=""
curS,curT=0,0

while curS<len(S):
    for i in range(26):
        if nexS[curS][i]==len(S):
            continue
        if nexT[curT][i]==len(T):
            Ans+=(chr)(0x61+i)
            print(Ans)
            exit(0)
        if inc[nexS[curS][i]+1]>=nexT[curT][i]+1:
            continue
        curS=nexS[curS][i]+1
        curT=nexT[curT][i]+1
        Ans+=(chr)(0x61+i)
        break
        
0