結果
問題 | No.2226 Hello, Forgotten World! |
ユーザー | maron8676 |
提出日時 | 2023-02-24 23:12:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 2,758 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 86,860 KB |
実行使用メモリ | 78,200 KB |
最終ジャッジ日時 | 2023-10-11 06:51:38 |
合計ジャッジ時間 | 2,184 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
71,536 KB |
testcase_01 | AC | 103 ms
77,060 KB |
testcase_02 | AC | 121 ms
78,200 KB |
testcase_03 | AC | 106 ms
77,128 KB |
testcase_04 | AC | 104 ms
76,964 KB |
testcase_05 | AC | 105 ms
77,308 KB |
testcase_06 | AC | 105 ms
76,916 KB |
testcase_07 | AC | 105 ms
77,256 KB |
testcase_08 | AC | 102 ms
76,892 KB |
testcase_09 | AC | 105 ms
77,196 KB |
ソースコード
from collections import defaultdict, deque from sys import stdin readline = stdin.readline def li(): return list(map(int, readline().split())) T = int(input()) case_list = [] for _ in range(T): N = int(input()) case_list.append(list(input())) # 後ろから探して最初に見つけた場所をhelloworldにする # 残りの?にはaを入れる hello = list('helloworld') for case_s in case_list: if ''.join(case_s).count(''.join(hello)) > 0: for j in range(len(case_s)): if case_s[j] == '?': case_s[j] = 'a' print(''.join(case_s)) continue possible = False for i in range(len(case_s) - 10, -1, -1): partial_possible = True for j in range(10): if case_s[i + j] != '?' and case_s[i + j] != hello[j]: partial_possible = False if partial_possible: # もう1つ前がhなら再チェック before_replace = False last_replace = False if i - 1 >= 0 and case_s[i - 1] == 'h': partial_possible = True for j in range(10): if case_s[i + j - 1] != '?' and case_s[i + j - 1] != hello[j]: partial_possible = False if partial_possible: before_replace = True elif i - 9 >= 0 and case_s[i - 9] == 'h': partial_possible = True for j in range(9): if case_s[i + j - 9] != '?' and case_s[i + j - 9] != hello[j]: partial_possible = False if partial_possible: last_replace = True if before_replace: for j in range(10): if case_s[i + j - 1] == '?': case_s[i + j - 1] = hello[j] possible = True for j in range(len(case_s)): if case_s[j] == '?': case_s[j] = 'a' elif last_replace: for j in range(10): if case_s[i + j - 9] == '?': case_s[i + j - 9] = hello[j] possible = True for j in range(len(case_s)): if case_s[j] == '?': case_s[j] = 'a' else: for j in range(10): if case_s[i + j] == '?': case_s[i + j] = hello[j] possible = True for j in range(len(case_s)): if case_s[j] == '?': case_s[j] = 'a' if possible: print(''.join(case_s)) break if not possible: print(-1)