結果

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

ソースコード

diff #

import math

def generate_99_bottles_lyrics():
    lyrics = []
    for n in range(99, -1, -1):
        if n > 0:
            bottles_current = f"{n} bottle{'s' if n != 1 else ''} of beer"
            line1 = f"{bottles_current} on the wall, {bottles_current}."
            if n == 1:
                line2 = "Take one down and pass it around, no more bottles of beer on the wall."
            else:
                next_n = n - 1
                bottles_next = f"{next_n} bottle{'s' if next_n != 1 else ''} of beer"
                line2 = f"Take one down and pass it around, {bottles_next} on the wall."
        else:
            line1 = "No more bottles of beer on the wall, no more bottles of beer."
            line2 = "Go to the store and buy some more, 99 bottles of beer on the wall."
        verse = f"{line1}\n{line2}\n"
        lyrics.append(verse)
    return ''.join(lyrics)

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

hello = "Hello, World!"
if s == hello:
    print("H")
elif s == "Q":
    print("Q")
elif s == generate_99_bottles_lyrics():
    print("9")
elif all(c == 'Q' for c in s):
    m = len(s)
    root = math.isqrt(m)
    if root * root == m:
        print('Q' * root)
    else:
        print(-1)
else:
    print(-1)
0