結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー Rapca1256
提出日時 2026-08-30 14:08:50
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 65 ms / 2,000 ms
+ 786µs
コード長 1,590 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 58 ms
コンパイル使用メモリ 14,720 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2026-10-26 14:22:29
合計ジャッジ時間 3,946 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

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