結果
| 問題 |
No.3277 Forever Monotonic Number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-22 20:59:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 355 ms / 4,000 ms |
| コード長 | 1,591 bytes |
| コンパイル時間 | 3,128 ms |
| コンパイル使用メモリ | 279,664 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-22 20:59:26 |
| 合計ジャッジ時間 | 6,125 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
using std::cin, std::cout, std::cerr;
using ll = long long;
const ll P = 998244353;
ll Pow(ll a, ll b) {
ll r = 1;
for(; b; b /= 2) {
if(b & 1)
r = r * a % P;
a = a * a % P;
}
return r;
}
ll Inv(ll x) { return Pow(x, P - 2); }
int main() {
std::ios::sync_with_stdio(false);
int T; cin >> T;
while(T --) {
std::function<bool(ll)> check = [&](ll x) -> bool {
if(x < 10) return true;
std::string s = std::to_string(x);
for(int i = 0; i + 1 < s.size(); i ++)
if(s[i] > s[i + 1])
return false;
ll y = 0;
for(char c : s)
y += c - '0';
return check(y);
};
auto make_mono = [](ll x) {
std::string s = std::to_string(x);
for(int i = 1; i < s.size(); i ++) if(s[i - 1] > s[i]) {
for(int j = i; j < s.size(); j ++)
s[j] = s[i - 1];
break;
}
return std::stoll(s);
};
ll n; cin >> n;
ll x = n + 1;
while(!check(x)) {
x ++;
x = make_mono(x);
}
x -= n + 1;
ll ans = (Pow(10, n + 1) - 1) * Inv(9) % P;
ll y = x / 8;
ans += (Pow(10, y) - 1) * Inv(9) % P * 8;
x -= y * 8;
ans += Pow(10, y) * x;
ans %= P;
cout << ans << '\n';
}
}