結果

問題 No.3081 Make Palindromic Multiple
ユーザー gew1fw
提出日時 2025-06-12 12:59:21
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,384 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 65,920 KB
最終ジャッジ日時 2025-06-12 13:06:24
合計ジャッジ時間 11,888 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

def generate_99_song():
    song = []
    for i in range(99, 0, -1):
        line1 = f"{i} bottles of beer on the wall, {i} bottles of beer.\n"
        song.append(line1)
        line2 = "Take one down and pass it around, "
        if i == 1:
            line2 += "no more bottles of beer on the wall.\n\n"
        else:
            line2 += f"{i-1} bottles of beer on the wall.\n\n"
        song.append(line2)
    return ''.join(song)

hello = "Hello, World!"
song = generate_99_song()

def is_hq9_plus_without_q(s, hello_str, song_str):
    index = 0
    code = []
    hello_len = len(hello_str)
    song_len = len(song_str)
    while index < len(s):
        if s.startswith(hello_str, index):
            code.append('H')
            index += hello_len
        elif song_len > 0 and s.startswith(song_str, index):
            code.append('9')
            index += song_len
        else:
            return None
    return ''.join(code) if index == len(s) else None

n = int(input())
s = input().strip()

if s == hello:
    print("H")
elif s == song:
    print("9")
else:
    q_count = s.count('Q')
    h_count = s.count('H')
    nine_count = s.count('9')
    if q_count == 1 and h_count == 0 and nine_count == 0:
        print(s)
    else:
        code = is_hq9_plus_without_q(s, hello, song)
        if code is not None:
            print(code)
        else:
            print(-1)
0