結果
問題 |
No.3277 Forever Monotonic Number
|
ユーザー |
![]() |
提出日時 | 2025-09-20 00:42:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 290 ms / 4,000 ms |
コード長 | 2,384 bytes |
コンパイル時間 | 5,133 ms |
コンパイル使用メモリ | 335,680 KB |
実行使用メモリ | 8,680 KB |
最終ジャッジ日時 | 2025-09-20 00:42:19 |
合計ジャッジ時間 | 8,635 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; using mint = modint998244353; const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } bool is_monotonic(int n) { auto s = to_string(n); rep(i, s.size() - 1) { if (s[i] > s[i + 1])return false; } return true; } int d_sum(int n) { int ret = 0; auto s = to_string(n); for (auto e : s)ret += e - '0'; return ret; } vector<long long>init_forever_monotonic(int len) { vector<bool>is_fm(len * 9 + 1); rep(i, is_fm.size()) { if (i <= 9 || (is_monotonic(i) && is_fm[d_sum(i)])) { is_fm[i] = true; } } vector<long long>fm_vec; vector<int>v; auto f = [&](vector<int>&v)->long long { long long ret = 0; for (auto e : v)ret = ret * 10 + e; return ret; }; auto dfs = [&](auto &&self)->void { if (v.size() > len)return; if (is_fm[std::reduce(std::begin(v), std::end(v))])fm_vec.push_back(f(v)); int l = v.empty() ? 1 : v.back(); rep2(i, l, 10) { v.push_back(i); self(self); v.pop_back(); } }; dfs(dfs); sort(all(fm_vec)); return fm_vec; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); auto list = init_forever_monotonic(15); mint inv9 = mint(9).inv(); int t; cin >> t; while (t--) { long long n; cin >> n; // 下階 // 11111111111111111 のn+1 long long sum = *lower_bound(list.begin(), list.end(), n + 1); long long x = (sum - (n + 1)) / 8; long long y = (sum - (n + 1)) % 8; // 11111111111111111y99999999999999みたくなるから // cout << sum << " " << x << " " << y << endl; mint ans = (mint(10).pow(n + 1) - 1)*inv9; ans += (mint(10).pow(x) - 1) * inv9 * 8; ans += y * mint(10).pow(x); cout << ans.val() << endl; // cout << sum << endl; } return 0; }