結果

問題 No.2226 Hello, Forgotten World!
ユーザー FromBooskaFromBooska
提出日時 2023-03-05 11:58:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 83,352 KB
最終ジャッジ日時 2023-10-18 04:49:42
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,520 KB
testcase_01 AC 378 ms
83,352 KB
testcase_02 AC 136 ms
76,540 KB
testcase_03 AC 122 ms
76,400 KB
testcase_04 AC 67 ms
75,568 KB
testcase_05 AC 130 ms
76,868 KB
testcase_06 AC 85 ms
75,812 KB
testcase_07 AC 94 ms
75,992 KB
testcase_08 AC 65 ms
75,560 KB
testcase_09 AC 99 ms
75,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ABC076Cが使えそうなので使う

# 全探索して、残った?にはaを入れればいい
# 当てはまる中の一番最後にあてはめるのがよいかと思ったが実はそうでもない
# たとえばS = ??z???, T = za
# 全探索可能なのだから解の全候補を出してその辞書順最小を出力

T = int(input())
for t in range(T):

    N = int(input())
    S = input()
    T = 'helloworld'
    M = len(T)

    candidates = []
    for i in range(N+1-M):
        test = True
        for j in range(M):
            if S[i+j] != '?' and S[i+j] != T[j]:
                test = False
        #print(test, S[i:i+M], T)
        if test == True:
            temp_ans1 = S[:i] + T + S[i+M:]
            temp_ans2 = ''
            for k in range(N):
                if temp_ans1[k] != '?':
                    temp_ans2 += temp_ans1[k]
                else:
                    temp_ans2 += 'a'
            candidates.append(temp_ans2)

    if len(candidates) == 0:
        print(-1)
    else:
        candidates.sort()
        print(candidates[0])

0