結果

問題 No.2226 Hello, Forgotten World!
コンテスト
ユーザー AP25
提出日時 2026-06-18 15:53:35
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,000 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 239 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 81,920 KB
最終ジャッジ日時 2026-06-18 15:53:37
合計ジャッジ時間 1,692 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 全探索して複数候補がある場合はできるだけ後ろにhelloworldをおいて余った?にはaをあてがう
# だめ
# h?????????dみたいな場合、後ろからだとhhelloworldとなるがhelloworlddを選ばない度だめ
# 候補全列挙でまにあうか?

T = int(input())

word = "helloworld"
num = len(word)

for _ in range(T):

    N = int(input())
    S = list(input())

    ids = []
    for s in range(N-num,-1,-1):
        if S[s] != "h" and S[s] != "?":
            continue

        if all(S[s+i] == word[i] or S[s+i] == "?" for i in range(num)):
            ids.append(s)

    if len(ids) == 0:
        print(-1)
        continue

    g = set()
    for idx in ids:
        Z = S[:]
        for i in range(num):
            if Z[idx+i] == "?":
                Z[idx+i] = word[i]

        for i in range(N):
            if Z[i] == "?":
                Z[i] = "a"
        g.add("".join(Z))

    g=sorted(g)
    print(g[0])
0