結果

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

ソースコード

diff #

import math

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

def check_case1(S):
    n = len(S)
    m = int(math.sqrt(n))
    if m * m != n:
        return None
    P = S[:m]
    for i in range(m):
        if S[i*m : (i+1)*m] != P:
            return None
    for c in P:
        if c not in {'H', 'Q'}:
            return None
    return P

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    S = input[1] if len(input) > 1 else ''

    result_case1 = check_case1(S)
    if result_case1 is not None:
        print(result_case1)
        return

    lyrics = generate_lyrics()
    if S == lyrics:
        print("9")
        return

    print(-1)

if __name__ == "__main__":
    main()
0