結果

問題 No.1186 長方形の敷き詰め
ユーザー CleyLCleyL
提出日時 2023-05-02 06:42:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 75,108 KB
実行使用メモリ 26,612 KB
最終ジャッジ日時 2024-05-01 00:36:17
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 35 ms
26,612 KB
testcase_23 AC 17 ms
16,236 KB
testcase_24 AC 27 ms
23,744 KB
testcase_25 AC 17 ms
15,992 KB
testcase_26 AC 20 ms
17,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const long long MOD = 998244353;

template <int mod>
struct Combination {
  long long n_max;
  vector<long long> fac, inv, finv;
  Combination(int n):n_max(n), fac(n+1,1), inv(n+1,1), finv(n+1,1){
    for(int i = 2; n > i; i++){
      fac[i] = (fac[i-1]*i)%mod;
      inv[i] = mod-((inv[mod%i]*(mod/i))%mod);
      finv[i] = (finv[i-1]*inv[i])%mod;
    }
  }

  long long C(int n, int r){
    if(n < r)return 0;
    if(max(n,r) > n_max)return 0;
    return (((fac[n]*finv[r])%mod)*finv[n-r])%mod;
  }
};
using comb = Combination<MOD>;

int main(){
  int n,m;cin>>n>>m;
  if(n > m)cout << 1 << endl;
  else if(n == 1)cout << m << endl;
  else{
    int x = m/n;
    comb c(m);
    long long ans = 0;
    for(int i = 0; x >= i; i++){
      ans = (ans+c.C(m-(i*(n-1)), i))%MOD;
    }
    cout << ans << endl;
  }
}
0