結果

問題 No.1967 Sugoroku Optimization
ユーザー monnumonnu
提出日時 2022-06-03 22:15:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 637 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 4,021 ms
コンパイル使用メモリ 231,848 KB
実行使用メモリ 34,772 KB
最終ジャッジ日時 2023-10-21 01:57:29
合計ジャッジ時間 10,041 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 636 ms
34,772 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 571 ms
31,340 KB
testcase_06 AC 611 ms
33,452 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 429 ms
24,476 KB
testcase_09 AC 320 ms
18,932 KB
testcase_10 AC 152 ms
10,748 KB
testcase_11 AC 21 ms
4,412 KB
testcase_12 AC 390 ms
22,628 KB
testcase_13 AC 193 ms
12,860 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 20 ms
4,348 KB
testcase_17 AC 24 ms
4,412 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 636 ms
34,772 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 637 ms
34,772 KB
testcase_23 AC 385 ms
22,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000
#define MOD 998244353
#define MAX 1000000

ll modpow(ll a,ll n,ll mod=MOD){
  ll res=1;
  a%=mod;
  while(n>0){
    if(n&1){
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a,ll mod=MOD){
  return modpow(a,mod-2,mod);
}

int main(){
  int N,K;
  cin>>N>>K;

  vector<vector<ll>> dp(K+1,vector<ll>(N+1,0));
  for(int i=0;i<=K;i++){
    dp[i][N]=1;
  }
  for(int i=K-1;i>=0;i--){
    vector<ll> sum=dp[i+1];
    for(int j=1;j<=N;j++){
      sum[j]+=sum[j-1];
      sum[j]%=MOD;
    }
    //dp[i][0]=sum[N]*modinv(N)%MOD;
    for(int j=0;j<N;j++){
      dp[i][j]=((sum[N]+MOD-sum[j])%MOD)*modinv(N-j)%MOD;
    }
  }

  cout<<dp[0][0]<<'\n';
}
0