結果

問題 No.1186 長方形の敷き詰め
ユーザー akaneakane
提出日時 2020-08-22 16:43:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 195,152 KB
実行使用メモリ 706,924 KB
最終ジャッジ日時 2024-04-23 10:49:44
合計ジャッジ時間 48,100 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX = 30000000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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



int main(){
    ios::sync_with_stdio(false);
    ll N,M; cin>>N>>M;
    COMinit();

    // 正方形を何カ所作れるか
    ll sq = M/N;
    cerr << "sq: " << sq << endl;
    // if(N>M){
    //     cout << 1 << endl; return 0;
    // }

    ll ans=0;
    for(ll i=0; i<=sq; i++){
        ll ret=0;

        // 棒の個数
        ll a = M - i*N; 
        // cerr << "a: " << a << endl;
        // ll x = modpow(a+1, i, mod);
        // cerr << "x: " << x << endl;
        ll num = a + i;
        ll x = COM(num,i);
        ans += x;
        ans %= mod;
    }
    cout << ans << endl;

}
0