結果

問題 No.1192 半部分列
ユーザー definedefine
提出日時 2020-08-05 14:57:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,241 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 81,644 KB
実行使用メモリ 190,540 KB
最終ジャッジ日時 2023-10-17 01:16:38
合計ジャッジ時間 16,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
161,108 KB
testcase_01 AC 399 ms
161,112 KB
testcase_02 AC 402 ms
161,112 KB
testcase_03 AC 394 ms
161,108 KB
testcase_04 AC 396 ms
161,112 KB
testcase_05 AC 404 ms
161,112 KB
testcase_06 AC 1,241 ms
190,540 KB
testcase_07 AC 516 ms
163,296 KB
testcase_08 AC 537 ms
163,256 KB
testcase_09 AC 505 ms
163,144 KB
testcase_10 AC 408 ms
161,120 KB
testcase_11 AC 410 ms
161,120 KB
testcase_12 AC 508 ms
163,216 KB
testcase_13 AC 465 ms
162,960 KB
testcase_14 AC 481 ms
163,276 KB
testcase_15 AC 483 ms
163,092 KB
testcase_16 AC 457 ms
161,924 KB
testcase_17 AC 485 ms
163,092 KB
testcase_18 AC 428 ms
161,756 KB
testcase_19 AC 455 ms
161,796 KB
testcase_20 AC 415 ms
161,596 KB
testcase_21 AC 456 ms
161,792 KB
testcase_22 AC 423 ms
161,776 KB
testcase_23 AC 523 ms
163,268 KB
testcase_24 AC 451 ms
161,768 KB
testcase_25 AC 455 ms
161,788 KB
testcase_26 AC 448 ms
161,612 KB
testcase_27 AC 460 ms
161,796 KB
権限があれば一括ダウンロードができます

ソースコード

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