結果
| 問題 | No.3277 Forever Monotonic Number |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-19 04:52:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,246 bytes |
| 記録 | |
| コンパイル時間 | 2,891 ms |
| コンパイル使用メモリ | 284,212 KB |
| 実行使用メモリ | 16,204 KB |
| 最終ジャッジ日時 | 2025-12-19 04:52:35 |
| 合計ジャッジ時間 | 12,573 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 1 TLE * 1 -- * 7 |
ソースコード
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/modint>
#endif
using namespace std;
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define use_ml998244353 using ml=atcoder::modint998244353;
namespace my{
auto&operator<<(ostream&o,const atcoder::modint998244353&x){return o<<(int)x.val();}
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
using vector<V>::vector;
ll size()const{return vector<V>::size();}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{
template<class T>struct pow_linear:vec<T>{pow_linear(T a,ll n):vec<T>(n+1,1){fo(i,n)(*this)[i+1]=(*this)[i]*a;}};
template<class T>struct pow10_linear:pow_linear<T>{
vec<T>repunit_table;
pow10_linear(ll n):pow_linear<T>(10,n),repunit_table(n+2){fo(i,n+1)repunit_table[i+1]=repunit_table[i]*10+1;}
};
template<class T=ll>T pow10(ll n){static const auto v=pow10_linear<T>(maxsize10<T>()-1);assert(n<v.size());return v[n];}
template<class T=ll>constexpr T at10(auto x,auto i){return x/pow10<T>(i)%10;}
}
namespace my{
template<class T>T digit_sum(T x,ll b){T r=x;while(x)r-=(x/=b)*(b-1);return r;}
template<class T>T digit_sum10(T x){return digit_sum(x,10);}
template<class T>T slice10(T x,ll l,ll r){return x%pow10<T>(r)/pow10<T>(l);}
template<class T>T range10(T x,ll l,ll r){return slice10<T>(x,l,r)*pow10<T>(l);}
}
namespace my{entry
void main(){
ll M=200;
vec<ll>dp(M);
fo(i,10)dp[i]=1;
auto is_mono=[&](ll x){
fo(i,size10(x)-1)if(at10(x,i+1)>at10(x,i))return 0;
return 1;
};
fo(i,10,M)if(dp[digit_sum10(i)]&&is_mono(i))dp[i]=1;
auto next_mono=[&](ll x){
fo(i,size10(x)+1){
if(at10(x,i)<9){
ll y=range10(x,i+1,size10(x));
fo(j,i+1)y+=(at10(x,i)+1)*pow10(j);
return y;
}
}
assert(0);
};
use_ml998244353
LL(T);
FO(T){
LL(N);
ll k=N+1;
for(;!is_mono(k);k=next_mono(k));
ll q=(k-(N+1))/8,r=(k-(N+1))%8;
pp((ml(10).pow(N+1)-1)/9+r*ml(10).pow(q)+(ml(10).pow(q)-1)/9*8);
}
}}