結果

問題 No.3157 Nabeatsu
ユーザー kyotoku1483
提出日時 2025-06-05 11:58:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 20,852 KB
最終ジャッジ日時 2025-06-05 11:58:22
合計ジャッジ時間 16,795 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    n = list(int(c) for c in input())
    for i in range(len(n)):
        if n[i] == 3:
            n[i] = 2
            for j in range(i + 1, len(n)):
                n[j] = 9
            break
    total = sum(n)
    while total % 3 == 0:
        if n[-1] > 0:
            if n[-1] == 4:
                n[-1] = 2
                total -= 2
            else:
                n[-1] -= 1
                total -= 1
        else:
            i = len(n) - 1
            while n[i] == 0:
                n[i] = 9
                total += 9
                i -= 1
            if n[i] == 4:
                n[i] = 2
                total -= 2
            else:
                n[i] -= 1
                total -= 1
    for x in n:
        print(x, end='')
    print()


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