結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー detteiuu
提出日時 2026-08-30 13:49:48
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 42 ms / 2,000 ms
+ 54µs
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 467 ms
コンパイル使用メモリ 64,188 KB
実行使用メモリ 59,356 KB
最終ジャッジ日時 2026-10-26 14:21:24
合計ジャッジ時間 4,291 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = input()
N = len(S)

if S < "4"*N:
    exit(print("5"*(N-1)))

ans = [-1]*N
small = False
idx = -1
for i in range(N):
    if not small:
        if 4 == int(S[i]):
            ans[i] = 4
        elif 5 == int(S[i]):
            ans[i] = 5
        elif 5 < int(S[i]):
            ans[i] = 5
            small = True
        else:
            ans[i] = 5
            idx = i
            small = True
    else:
        ans[i] = 5

if idx != -1:
    for i in reversed(range(idx)):
        if S[i] == "5":
            ans[i] = 4
            for j in range(i+1, idx):
                ans[j] = 5
            break

print("".join(map(str, ans)))
0