結果
| 問題 | No.3658 Darumaka Number 2 |
| コンテスト | |
| ユーザー |
aqua
|
| 提出日時 | 2026-08-30 14:22:03 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| + 747µs | |
| コード長 | 1,136 bytes |
| 記録 | |
| コンパイル時間 | 2,048 ms |
| コンパイル使用メモリ | 331,716 KB |
| 実行使用メモリ | 11,516 KB |
| 最終ジャッジ日時 | 2026-08-30 14:23:09 |
| 合計ジャッジ時間 | 4,345 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string N; cin >> N;
string ans;
// f: strictly less than N
auto solve = [&](auto self, int i, bool f) -> bool {
if (i == N.size()) return true;
if (f) {
ans += '5';
self(self, i + 1, true);
return true;
}
if (N[i] > '5') {
ans += '5';
if (self(self, i + 1, true)) return true;
} else if (N[i] == '5') {
ans += '5';
if (self(self, i + 1, f)) return true;
ans += '4';
if (self(self, i + 1, true)) return true;
} else if (N[i] == '4') {
ans += '4';
if (self(self, i + 1, f)) return true;
}
ans.pop_back();
return false;
};
if (N[0] < '4') {
solve(solve, 1, true);
} else {
solve(solve, 0, false);
}
cout << ans << '\n';
}
aqua