結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー detteiuu
提出日時 2026-08-30 13:49:48
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 78 ms / 2,000 ms
+ 916µs
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 95,852 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2026-08-30 13:49:55
合計ジャッジ時間 5,424 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

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