結果

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

ソースコード

diff #

def generate_h_str():
    return "Hello, World!"

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

H_STR = generate_h_str()
NINE_STR = generate_nine_str()

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

if s == H_STR:
    print("H")
elif s == NINE_STR:
    print("9")
elif s == "Q":
    print("Q")
else:
    # Check if all characters are 'Q's and length is a perfect square
    all_q = True
    for c in s:
        if c != 'Q':
            all_q = False
            break
    if all_q:
        m = int(len(s) ** 0.5)
        if m * m == len(s):
            print('Q' * m)
            exit()
    # Check if exactly one 'Q' and no 'H' or '9'
    q_count = 0
    h_count = 0
    nine_count = 0
    for c in s:
        if c == 'Q':
            q_count += 1
        elif c == 'H':
            h_count += 1
        elif c == '9':
            nine_count += 1
    if q_count == 1 and h_count == 0 and nine_count == 0:
        print(s)
        exit()
    # None of the cases matched
    print(-1)
0