結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー Rapca1256
提出日時 2026-08-30 14:08:50
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 139 ms / 2,000 ms
+ 883µs
コード長 1,590 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 448 ms
コンパイル使用メモリ 21,412 KB
実行使用メモリ 16,632 KB
最終ジャッジ日時 2026-08-30 14:09:02
合計ジャッジ時間 8,621 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import math
#from collections import deque, defaultdict, Counter
#import heapq
#import bisect
#import itertools
#import functools

# 外部ライブラリ(AtCoder環境で利用可能)
#from sortedcontainers import SortedList, SortedSet, SortedDict
#from atcoder.dsu import DSU
#from atcoder.segtree import SegTree
#from atcoder.lazysegtree import LazySegTree
#from atcoder.fenwicktree import FenwickTree

# 入力高速化
#input = sys.stdin.readline
# 再帰回数上限

# よくあるmod
#MOD = 1000000007
MOD = 998244353

def solve():
    # 解答ここから
    N = input()
    compromise = -1
    compromise_req = False
    for i in range(len(N)-1, -1, -1):
        if int(N[i]) == 5 and compromise_req:
            compromise = i
            compromise_req = False
        elif int(N[i]) >= 6:
            compromise_req = False
            compromise = -1
        elif int(N[i]) <= 3:
            compromise_req = True
    if compromise_req:
        if len(N) >= 2:
            print("".join(["5"] * (len(N) - 1)))
        else:
            print("4")
        return
    comed = False
    for i in range(len(N)):
        if comed:
            print("5", end="")
            continue
        if compromise == i:
            print("4", end="")
            comed = True
            continue
        if int(N[i]) == 5:
            print("5", end="")
        elif int(N[i]) >= 6:
            print("5", end="")
            comed = True
        else:
            print("4", end="")
    print()


if __name__ == '__main__':
    T = 1
    for _ in range(T):
        solve()
0