結果
| 問題 | No.3658 Darumaka Number 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-30 14:04:28 |
| 言語 | D (dmd 2.113.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| + 589µs | |
| コード長 | 1,456 bytes |
| 記録 | |
| コンパイル時間 | 3,140 ms |
| コンパイル使用メモリ | 193,920 KB |
| 実行使用メモリ | 19,768 KB |
| 最終ジャッジ日時 | 2026-08-30 14:06:26 |
| 合計ジャッジ時間 | 6,169 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
import std;
void main () {
auto N = readln.chomp.map!(a => a - '0').array;
const int L = N.length.to!int;
const dig = [4, 5];
bool[Tuple!(int, bool)] memo;
bool dp (int pos, bool less) {
auto key = tuple(pos, less);
if (key in memo) {
return memo[key];
}
if (pos == L) {
return true;
}
bool ret = false;
foreach (nex; dig) {
if (!less && N[pos] < nex) {
continue;
}
bool nless = less || nex < N[pos];
ret = ret || dp(pos + 1, nless);
}
return memo[key] = ret;
}
bool less = false;
auto ans = new int[](0);
bool fi = false;
foreach (i; 0 .. L) {
foreach_reverse (nex; dig) {
if (!less && N[i] < nex) {
continue;
}
bool nless = less || nex < N[i];
if (dp(i + 1, nless)) {
if (i == 0) {
fi = true;
}
ans ~= nex;
less = nless;
break;
}
}
}
if (fi) {
writefln("%(%s%)", ans);
}
else {
writeln(replicate("5", L - 1));
}
}
void read (T...) (string S, ref T args) {
import std.conv : to;
import std.array : split;
auto buf = S.split;
foreach (i, ref arg; args) {
arg = buf[i].to!(typeof(arg));
}
}