結果

問題 No.3081 Make Palindromic Multiple
ユーザー lam6er
提出日時 2025-04-16 15:26:33
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,730 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 67,652 KB
最終ジャッジ日時 2025-04-16 15:28:26
合計ジャッジ時間 10,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

song_99 = generate_99_song()

if s == song_99:
    print('9')
elif s == "Hello, world!":
    print('H')
else:
    q_count = s.count('Q')
    other_commands = any(c in 'H9+' for c in s)
    if q_count == 1 and not other_commands:
        print(s)
    else:
        divisors = []
        for m in range(1, int(n**0.5) + 1):
            if n % m == 0:
                divisors.append(m)
                if m != n // m:
                    divisors.append(n // m)
        divisors.sort()
        found = False
        for m in divisors:
            if n % m != 0:
                continue
            k = n // m
            candidate = s[:k]
            if candidate * m != s:
                continue
            q_candidate = candidate.count('Q')
            if q_candidate != m:
                continue
            if any(c in 'H9+' for c in candidate):
                continue
            print(candidate)
            found = True
            break
        if not found:
            print(-1)
0