結果

問題 No.1186 長方形の敷き詰め
ユーザー akaneakane
提出日時 2020-08-22 16:34:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,498 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 196,024 KB
実行使用メモリ 15,612 KB
最終ジャッジ日時 2024-04-23 10:36:23
合計ジャッジ時間 5,320 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
15,444 KB
testcase_01 AC 13 ms
15,524 KB
testcase_02 AC 13 ms
15,516 KB
testcase_03 AC 12 ms
15,360 KB
testcase_04 AC 13 ms
15,372 KB
testcase_05 AC 14 ms
15,580 KB
testcase_06 AC 13 ms
15,548 KB
testcase_07 AC 13 ms
15,608 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 AC 13 ms
15,508 KB
testcase_12 AC 13 ms
15,412 KB
testcase_13 AC 13 ms
15,336 KB
testcase_14 AC 13 ms
15,284 KB
testcase_15 AC 13 ms
15,504 KB
testcase_16 AC 12 ms
15,608 KB
testcase_17 AC 12 ms
15,284 KB
testcase_18 AC 13 ms
15,408 KB
testcase_19 AC 12 ms
15,404 KB
testcase_20 AC 13 ms
15,544 KB
testcase_21 AC 13 ms
15,484 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 510000;
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