結果

問題 No.2530 Yellow Cards
ユーザー umezoumezo
提出日時 2023-11-03 23:49:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 771 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 201,880 KB
実行使用メモリ 122,392 KB
最終ジャッジ日時 2023-11-03 23:49:33
合計ジャッジ時間 5,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,600 KB
testcase_01 WA -
testcase_02 AC 24 ms
25,592 KB
testcase_03 WA -
testcase_04 AC 3 ms
5,596 KB
testcase_05 AC 23 ms
25,592 KB
testcase_06 AC 2 ms
5,596 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll dp[5050][5050];
ll modpow(ll x,ll n){
  x%=MOD;
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,k;
  cin>>n>>k;
  ll a=modpow(n,MOD-2);
  dp[0][0]=n;
  for(int i=0;i<k;i++){
    for(int j=0;j<=n;j++){
      if(dp[i][j]==0) continue;
      if(j) dp[i+1][j-1]=(dp[i+1][j-1]+(dp[i][j]+1)*j%MOD*a%MOD)%MOD;
      dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*(n-j)%MOD*a%MOD)%MOD;
    }
  }
  ll ans=0;
  for(int j=0;j<=n;j++) ans=(ans+dp[k][j]);
  cout<<ans<<endl;
  
  return 0;
}
0