結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー まぬお
提出日時 2026-08-30 14:09:14
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,374 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,547 ms
コンパイル使用メモリ 95,468 KB
実行使用メモリ 107,340 KB
最終ジャッジ日時 2026-08-30 14:09:47
合計ジャッジ時間 10,753 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 7 RE * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations, groupby
from heapq import heappop, heappush
import math, sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def printl(li, sep=" "): print(sep.join(map(str, li)))
def yn(flag): print(Yes if flag else No)
_int = lambda x: int(x)-1
MOD = 998244353 #10**9+7
INF = 1<<60
Yes, No = "Yes", "No"

nums = list(map(int, input()))
N = len(nums)

M = 2*2
dp = [[-1]*M for _ in range(N+1)]
def ind(small, d): return small*2+d
dp[0][ind(0, 0)] = 0
for i in range(N):
    num = nums[i]
    for d in range(2):
        for small in range(2):
            key = ind(small, d)
            if dp[i][key] < 0: continue
            for nd in [4, 5]:
                if not small and nd > num: break
                nsmall = small | (1 if nd < num else 0)
                nkey = ind(nsmall, nd-4)
                dp[i+1][nkey] = key
ans = 0
for d in reversed(range(2)):
    for small in range(2):
        if dp[N][ind(small, d)] < 0: continue
        i = ind(small, d)
        cur = N
        li = []
        for _ in range(N):
            li.append(str(i%2+4))
            i = dp[cur][i]
            cur -= 1
        ans = max(ans, int("".join(li)))
        break
    else: continue
    break

ans = max(ans, int("5"*(N-1)))
print(ans)
0