結果
| 問題 | No.3277 Forever Monotonic Number | 
| コンテスト | |
| ユーザー |  Kude | 
| 提出日時 | 2025-09-19 22:03:15 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 132 ms / 4,000 ms | 
| コード長 | 1,880 bytes | 
| コンパイル時間 | 3,477 ms | 
| コンパイル使用メモリ | 305,928 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-09-19 22:03:22 | 
| 合計ジャッジ時間 | 5,235 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 9 | 
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;
bool memo[1000];
} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  rep(x, 1000) {
    if (x < 10) {
      memo[x] = true;
    } else {
      auto s = to_string(x);
      bool ok = true;
      rep(i, ssize(s) - 1) ok &= s[i] <= s[i+1];
      int sm = 0;
      for (char c : s) sm += c - '0';
      ok &= memo[sm];
      memo[x] = ok;
    }
  }
  int tt;
  cin >> tt;
  while (tt--) {
    ll n;
    cin >> n;
    n++;
    string s = to_string(n);
    reverse(all(s));
    rrep(i, ssize(s) - 1) if (s[i] < s[i+1]) {
      rep(j, i + 1) s[j] = s[i+1];
      break;
    }
    while (true) {
      int now = 0;
      for (char c : s) now += c - '0';
      if (memo[now]) break;
      int i = 0;
      while (i < ssize(s) && s[i] == '9') i++;
      if (i == ssize(s)) s += '0';
      s[i]++;
      rep(j, i) s[j] = s[i];
    }
    ll sm = 0;
    for (char c : s | views::reverse) sm = 10 * sm + (c - '0');
    sm -= n;
    mint ans = (mint(10).pow(n) - 1) / 9;
    ll q = sm / 8;
    int r = sm % 8;
    ans += (mint(10).pow(q) - 1) / 9 * 8;
    ans += mint(10).pow(q) * r;
    cout << ans.val() << '\n';
  }
}
            
            
            
        