結果

問題 No.1192 半部分列
ユーザー lam6er
提出日時 2025-04-16 16:41:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 104,388 KB
最終ジャッジ日時 2025-04-16 16:42:14
合計ジャッジ時間 3,011 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    S = sys.stdin.readline().strip()
    T = sys.stdin.readline().strip()

    # Check if there's any character in S not present in T
    t_chars = set(T)
    for c in 'abcdefghijklmnopqrstuvwxyz':
        if c in S and c not in t_chars:
            print(c)
            return

    # Preprocess T for subsequence checks
    n_t = len(T)
    next_pos = [[n_t] * 26 for _ in range(n_t + 1)]
    for i in range(n_t - 1, -1, -1):
        for c in range(26):
            next_pos[i][c] = next_pos[i + 1][c]
        current_ord = ord(T[i]) - ord('a')
        next_pos[i][current_ord] = i

    # Check if S is a subsequence of T
    current_t = 0
    for c in S:
        c_ord = ord(c) - ord('a')
        pos = next_pos[current_t][c_ord]
        if pos >= n_t:
            print(S)
            return
        current_t = pos + 1

    # If S is a subsequence of T
    print(-1)

if __name__ == "__main__":
    main()
0