結果

問題 No.1964 sum = length
ユーザー eQeeQe
提出日時 2024-10-17 17:11:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,448 ms / 2,000 ms
コード長 2,601 bytes
コンパイル時間 5,779 ms
コンパイル使用メモリ 313,712 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-17 17:12:02
合計ジャッジ時間 27,569 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
namespace my{
using ml=atcoder::modint998244353;
auto&operator>>(std::istream&i,ml&x){int t;i>>t;x=t;return i;}
auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();}
void main();
void solve();
}
int main(){my::main();}
namespace my{
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll ij=n;ij--;)
#define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a)
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ulll=__uint128_t;
using lll=__int128_t;
istream&operator>>(istream&i,ulll&x){ull t;i>>t;x=t;return i;}
ostream&operator<<(ostream&o,const ulll&x){return(x<10?o:o<<x/10)<<ll(x%10);}
istream&operator>>(istream&i,lll&x){ll t;i>>t;x=t;return i;}
ostream&operator<<(ostream&o,const lll&x){return o<<string(x<0,'-')<<ulll(x>0?x:-x);}
auto range(bool s,ll a,ll b=1e18,ll c=1){if(b==1e18)b=a,(s?b:a)=0;return array{a-s,b,c};}
constexpr char nl=10;
constexpr char sp=32;
lll pw(lll x,ll n,ll m=0){assert(n>=0);lll r=1;while(n)n&1?r*=x:r,x*=x,m?r%=m,x%=m:r,n>>=1;return r;}
bool in(auto l,auto m,auto r){return l<=m&&m<r;}

template<class V>concept vectorial=is_base_of_v<vector<typename V::value_type>,V>;
template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;}
template<class V>ostream&operator<<(ostream&o,const vector<V>&v){fe(v,e)o<<e<<string(&e!=&v.back(),vectorial<V>?nl:sp);return o;}

template<class V>struct vec:vector<V>{
  using vector<V>::vector;
  vec(const vector<V>&v){vector<V>::operator=(v);}

  vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;}
  vec operator^(const vec&u)const{return vec{*this}^=u;}
  vec&operator++(){fe(*this,e)++e;return*this;}
  vec&operator--(){fe(*this,e)--e;return*this;}
};

void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
void lin(auto&...a){(cin>>...>>a);}
template<char c=sp>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<nl;}

void main(){io();ll T=1;fo(T)solve();}
void solve(){
  LL(N);

  const ll D=3;//桁数の上限
  ll offset=D*N+N-1;
  ll M=offset*2+1;
  vec<ml>dp(M);

  dp[offset]=1;
  fo(i,N){
    vec<ml>ndp(M);
    fo(j,M){
      if(dp[j]==0)continue;
      fo(d,D+1){
        fo(x,pw(10,d),pw(10,d+1)){
          ll nj=j-(d+1)-(i>0)+x;
          if(in(0,nj,M))ndp[nj]+=dp[j];
        }
      }
    }
    swap(dp,ndp);
  }
  pp(dp[offset]);
}}
0