結果

問題 No.1192 半部分列
ユーザー lam6er
提出日時 2025-04-16 16:41:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 76,496 KB
最終ジャッジ日時 2025-04-16 16:42:03
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

def is_subsequence(s, t):
    it = iter(t)
    for c in s:
        found = False
        while True:
            try:
                curr = next(it)
                if curr == c:
                    found = True
                    break
            except StopIteration:
                break
        if not found:
            return False
    return True

s = input().strip()
t = input().strip()

# Step 1: Check for any character in S not present in T
t_chars = set(t)
missing_chars = []
for c in s:
    if c not in t_chars:
        missing_chars.append(c)
if missing_chars:
    print(min(missing_chars))
    exit()

# Step 2: Check for characters where count in S exceeds count in T
count_s = Counter(s)
count_t = Counter(t)
for c in 'abcdefghijklmnopqrstuvwxyz':
    if count_s.get(c, 0) > count_t.get(c, 0):
        required = count_t[c] + 1
        print(c * required)
        exit()

# Step 3: Check if S is a subsequence of T
if not is_subsequence(s, t):
    print(s)
else:
    print(-1)
0