結果

問題 No.1186 長方形の敷き詰め
ユーザー akaneakane
提出日時 2020-08-22 16:41:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 196,172 KB
実行使用メモリ 238,144 KB
最終ジャッジ日時 2024-04-23 10:41:12
合計ジャッジ時間 14,914 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 431 ms
237,728 KB
testcase_01 AC 436 ms
237,960 KB
testcase_02 AC 432 ms
237,812 KB
testcase_03 AC 428 ms
237,940 KB
testcase_04 AC 434 ms
237,892 KB
testcase_05 AC 442 ms
237,852 KB
testcase_06 AC 432 ms
237,840 KB
testcase_07 AC 441 ms
238,012 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 434 ms
237,896 KB
testcase_12 AC 423 ms
237,708 KB
testcase_13 AC 438 ms
237,816 KB
testcase_14 AC 435 ms
237,920 KB
testcase_15 AC 443 ms
238,044 KB
testcase_16 AC 432 ms
237,920 KB
testcase_17 AC 433 ms
237,760 KB
testcase_18 AC 434 ms
237,892 KB
testcase_19 AC 432 ms
238,024 KB
testcase_20 AC 443 ms
237,940 KB
testcase_21 AC 434 ms
237,984 KB
testcase_22 AC 433 ms
237,872 KB
testcase_23 AC 427 ms
237,804 KB
testcase_24 AC 419 ms
237,928 KB
testcase_25 AC 409 ms
238,040 KB
testcase_26 AC 454 ms
237,916 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 = 10000000;
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