結果
問題 |
No.3277 Forever Monotonic Number
|
ユーザー |
|
提出日時 | 2025-09-21 12:25:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 168 ms / 4,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 69,116 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-21 12:25:59 |
合計ジャッジ時間 | 2,409 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include<iostream> #include<cassert> #include<atcoder/modint> using namespace std; using mint=atcoder::modint998244353; bool fm[150]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for(int n=0;n<10;n++)fm[n]=true; for(int n=10;n<150;n++) { string s=to_string(n); bool ok=true; for(int i=1;i<s.size();i++)if(s[i-1]>s[i])ok=false; if(ok) { int c=0; for(char d:s)c+=d-'0'; if(fm[c])fm[n]=true; } } int T;cin>>T; for(;T--;) { long N;cin>>N; long V=N+1; while(true) { string s=to_string(V); {//m for(int i=1;i<s.size();) { if(s[i-1]<=s[i])i++; else { char c=s[i-1]; while(i<s.size())s[i++]=c; } } } V=stoll(s); int c=0; for(char d:s)c+=d-'0'; if(fm[c])break; V++; } mint ans=0; {//11...1 (N+1 keta) ans=(mint(10).pow(N+1)-1)/9; V-=N+1; } if((N+1)*8>=V) {//1 -> 9 (+8) long t=min(V/8,N+1); ans+=(mint(10).pow(t)-1)/9*8; V-=t*8; ans+=mint(10).pow(t)*V; } else {assert(false); ans+=(mint(10).pow(N+1)-1)/9*8; V-=(N+1)*8; ans+=(mint(10).pow(V/9)-1+V%9*mint(10).pow(V/9))*mint(10).pow(N+1); } cout<<ans.val()<<"\n"; } }