結果

問題 No.1192 半部分列
ユーザー shotoyooshotoyoo
提出日時 2021-05-25 00:49:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,267 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 82,524 KB
最終ジャッジ日時 2024-04-21 10:12:31
合計ジャッジ時間 4,319 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
59,920 KB
testcase_01 AC 34 ms
52,616 KB
testcase_02 AC 35 ms
53,608 KB
testcase_03 AC 34 ms
52,956 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
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 sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがi【以上】のインデックスで最初に現れる位置n[i][c]
    ない場合はNone
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if isinstance(s[0], str):
        oa = ord("a")
        s = [ord(c)-oa for c in s]
    if target is None:
        target = list(range(26))
    d = {c:-1 for c in target}
    nx = [[-1]*len(s) for _ in range(len(target))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[j][i] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[j][i]==-1:
                        nx[j][i] = nx[j][0]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[j][i] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[j][i]==-1:
                        nx[j][i] = nx[j][-1]
    return nx
s = input()
t = input()
n = len(s)
m = len(t)
l = [m]
j = m-1
for i in range(n)[::-1]:
    c = s[i]
    while j>=0 and t[j]!=c:
        j -= 1
    l.append(j)
    if j>=0:
        j -= 1
l = l[::-1]
if j>=0:
    ans = -1
else:
    nx = snx(s)
    tnx = snx(t)
    ans = []
    i = 0
    j = 0
    done = 0
    while 1:
        for c in range(26):
            if not nx[c][i]>=0:
                continue
            if j>=m or tnx[c][j]==-1:
                ans.append(c)
                done = 1
                break
            elif l[nx[c][i]] < tnx[c][j]:
                ans.append(c)
                i = nx[c][i] + 1
                j = tnx[c][j] + 1
                break
        if done:
            break
    ans = "".join([chr(ord("a")+c) for c in ans])
print(ans)
0