結果
| 問題 | No.3658 Darumaka Number 2 |
| コンテスト | |
| ユーザー |
まぬお
|
| 提出日時 | 2026-08-30 14:25:01 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,363 bytes |
| 記録 | |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 96,104 KB |
| 実行使用メモリ | 111,780 KB |
| 最終ジャッジ日時 | 2026-08-30 14:25:10 |
| 合計ジャッジ時間 | 7,222 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 WA * 15 |
ソースコード
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
# print(dp)
ans = []
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
li.reverse()
ans = max(ans, li)
if len(ans) == 0:
ans = [5]*(N-1)
printl(ans, "")
まぬお