結果
問題 |
No.3277 Forever Monotonic Number
|
ユーザー |
|
提出日時 | 2025-09-19 21:55:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,444 ms / 4,000 ms |
コード長 | 2,802 bytes |
コンパイル時間 | 1,718 ms |
コンパイル使用メモリ | 171,200 KB |
実行使用メモリ | 9,068 KB |
最終ジャッジ日時 | 2025-09-19 21:56:15 |
合計ジャッジ時間 | 18,124 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int p=998244353; int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}} int inv(int x) {return po(x,p-2);} mt19937 rnd; #define app push_back #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__) #define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc<v.size();++izxc) {cout << v[izxc];if(izxc+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0) #else #define debug(...) #define debugv(v) #endif #define lob(a,x) lower_bound(all(a),x) #define upb(a,x) upper_bound(all(a),x) #define print(x) cout<<(x)<<'\n' #define suma(a) accumulate(all(a),0LL) #define maxpos(a) max_element(all(a))-a.begin() #define minpos(a) min_element(all(a))-a.begin() #define maxa(a) *max_element(all(a)) #define mina(a) *min_element(all(a)) int inv9; int f(int len) { return ((po(10,len)-1)*inv9)%p; } bool monot(int N) { vector<int> o; while(N) { o.app(N%10); N/=10; } reverse(all(o)); return is_sorted(all(o)); } int s(int N) { vector<int> o; while(N) { o.app(N%10); N/=10; } return accumulate(all(o),0LL); } bool check(int N) { if(N<=9) return 1; if(!monot(N)) return 0; N=s(N); return check(N); } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); inv9=inv(9); vector<int> tot; int lst; for(int mask=0;mask<(1<<24);++mask) { if(__builtin_popcount(mask)==9) { lst=mask; vector<int> al; al.app(-1); for(int i=0;i<24;++i) { if(mask & (1<<i)) { al.app(i); } } al.app(24); vector<int> cnt(10); for(int i=0;i<=9;++i) { cnt[i]=al[i+1]-al[i]-1; } int N=0; for(int i=0;i<=9;++i) { for(int j=0;j<cnt[i];++j) { N=N*10; N+=i; } } if(check(N)) tot.app(N); } } sort(all(tot)); int t;cin>>t; while(t--) { int n;cin>>n; //int p10=1;for(int i=0;i<n;++i) p10*=10; //int hh=*lower_bound(all(tot),p10); //debug(hh%p); //int z=n+1;while(!check(z)) ++z; //debug(z); int h=*upper_bound(all(tot),n); int len=n+1; int ans=f(len); h-=(n+1); debug(h); int o=h/8; ans+=8*f(o);ans%=p; h-=8*o; debug(o); ans+=po(10,o)*h;ans%=p; cout<<(ans%p+p)%p<<'\n'; } return 0; }