結果

問題 No.1186 長方形の敷き詰め
ユーザー akaneakane
提出日時 2020-08-22 17:00:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,497 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 198,688 KB
実行使用メモリ 50,528 KB
最終ジャッジ日時 2023-08-05 13:54:25
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
50,228 KB
testcase_01 AC 43 ms
50,312 KB
testcase_02 AC 43 ms
50,292 KB
testcase_03 AC 44 ms
50,528 KB
testcase_04 AC 43 ms
50,340 KB
testcase_05 AC 43 ms
50,328 KB
testcase_06 AC 43 ms
50,224 KB
testcase_07 AC 46 ms
50,452 KB
testcase_08 AC 45 ms
50,372 KB
testcase_09 AC 46 ms
50,416 KB
testcase_10 AC 46 ms
50,312 KB
testcase_11 AC 47 ms
50,380 KB
testcase_12 AC 46 ms
50,268 KB
testcase_13 AC 52 ms
50,528 KB
testcase_14 AC 65 ms
50,244 KB
testcase_15 AC 67 ms
50,452 KB
testcase_16 AC 46 ms
50,412 KB
testcase_17 AC 45 ms
50,420 KB
testcase_18 AC 46 ms
50,240 KB
testcase_19 AC 44 ms
50,304 KB
testcase_20 AC 45 ms
50,244 KB
testcase_21 AC 45 ms
50,300 KB
testcase_22 AC 52 ms
50,372 KB
testcase_23 AC 44 ms
50,292 KB
testcase_24 AC 46 ms
50,264 KB
testcase_25 AC 48 ms
50,260 KB
testcase_26 AC 46 ms
50,248 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 2000000;
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==1){
        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