結果

問題 No.1964 sum = length
ユーザー yamakeyamake
提出日時 2022-06-04 12:43:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 2,217 bytes
コンパイル時間 4,261 ms
コンパイル使用メモリ 236,596 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 02:38:29
合計ジャッジ時間 7,614 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
testcase_15 AC 19 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 126 ms
4,348 KB
testcase_23 AC 119 ms
4,348 KB
testcase_24 AC 47 ms
4,348 KB
testcase_25 AC 60 ms
4,348 KB
testcase_26 AC 143 ms
4,348 KB
testcase_27 AC 81 ms
4,348 KB
testcase_28 AC 55 ms
4,348 KB
testcase_29 AC 101 ms
4,348 KB
testcase_30 AC 62 ms
4,348 KB
testcase_31 AC 143 ms
4,348 KB
testcase_32 AC 24 ms
4,348 KB
testcase_33 AC 23 ms
4,348 KB
testcase_34 AC 117 ms
4,348 KB
testcase_35 AC 33 ms
4,348 KB
testcase_36 AC 70 ms
4,348 KB
testcase_37 AC 98 ms
4,348 KB
testcase_38 AC 158 ms
4,348 KB
testcase_39 AC 58 ms
4,348 KB
testcase_40 AC 63 ms
4,348 KB
testcase_41 AC 132 ms
4,348 KB
testcase_42 AC 168 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<"\n";
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const int inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

#include<atcoder/all>
using namespace atcoder;
using mint = modint998244353;

template<class T>
struct Binom{
    long long n;
    bool flag=false;
    vector<T> kaijo,inv_kaijo;
    Binom(int N){
        n=N;
        kaijo.push_back(1);
        for(long long i=1;i<=n;i++){
            kaijo.push_back((kaijo[i-1]*i));
        }
    }
    void invList(){
      inv_kaijo.push_back(1);
      flag=true;
      for(int i=1;i<=n;++i){
        inv_kaijo.push_back(1/kaijo[i]);
      }
    }
    T binom(long long N,long long K){
        if(N<0||K<0)return 0;
        if(N<K)return 0;
        if(flag)return kaijo[N]*inv_kaijo[K]*inv_kaijo[N-K];
        T res=kaijo[N]/kaijo[K];//
        res/=kaijo[N-K];
        return res;
    }
    T binom2(mint N,long long K){
        // O(K)で2項係数を返す
        T res=1/kaijo[K];
        for(long long i=0;i<K;++i){
            res*=(N-i);
        }
        return res;
    }
};

signed main(){
    int n;cin>>n;
    vector<int> a;
    rep(i,9)a.push_back(i);
    a.push_back(8);
    for(int i=9;i<98;++i)a.push_back(i);
    a.push_back(97);
    for(int i=98;i<=200;++i)a.push_back(i);
    vector<vector<mint>> dp(n+1,vector<mint>(n,0));
    dp[0][0]=1;
    Binom<mint> binom(n+1000);
    binom.invList();
    for(auto& x:a){
        auto ndp=dp;
        rep(i,n){
            rep1(j,n){
                if(i+j>n)break;
                if(x*j>=n)break;
                rep(k,n){
                    if(k+x*j>=n)break;
                    ndp[i+j][k+x*j]+=dp[i][k]*binom.binom(n-i,j);
                }
            }
        }
        swap(dp,ndp);
    }
    cout<<dp[n][n-1].val()<<"\n";
    return 0;
}
0