結果

問題 No.2164 Equal Balls
ユーザー ぷらぷら
提出日時 2022-12-15 04:12:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,041 bytes
コンパイル時間 4,957 ms
コンパイル使用メモリ 265,768 KB
実行使用メモリ 13,284 KB
最終ジャッジ日時 2024-04-26 07:36:04
合計ジャッジ時間 45,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 53 ms
6,972 KB
testcase_09 AC 37 ms
5,860 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 93 ms
8,940 KB
testcase_12 AC 55 ms
6,976 KB
testcase_13 AC 36 ms
5,608 KB
testcase_14 AC 46 ms
5,904 KB
testcase_15 AC 90 ms
8,900 KB
testcase_16 AC 46 ms
6,252 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 67 ms
7,896 KB
testcase_19 AC 110 ms
10,840 KB
testcase_20 AC 60 ms
7,332 KB
testcase_21 AC 12 ms
5,376 KB
testcase_22 AC 14 ms
5,376 KB
testcase_23 AC 2,797 ms
6,336 KB
testcase_24 AC 1,446 ms
12,064 KB
testcase_25 AC 2,573 ms
5,376 KB
testcase_26 AC 486 ms
12,304 KB
testcase_27 AC 1,747 ms
12,820 KB
testcase_28 AC 1,807 ms
12,952 KB
testcase_29 AC 888 ms
5,956 KB
testcase_30 AC 1,810 ms
9,736 KB
testcase_31 AC 3,489 ms
5,888 KB
testcase_32 AC 2,076 ms
12,020 KB
testcase_33 AC 1,783 ms
5,376 KB
testcase_34 AC 2,336 ms
6,392 KB
testcase_35 AC 491 ms
5,376 KB
testcase_36 AC 4,203 ms
13,284 KB
testcase_37 AC 4,186 ms
5,632 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

constexpr int mod = 998244353;

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

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 605; 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;
}

long long choose(int n,int k) {
    if(n < 0 || k < 0) return 0;
    if(n == 0) return 1;
    return COM(n+k-1,k-1);
}

int main() {
    COMinit();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vector<int>A(N),B(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    vector<vector<int>>dp(M,vector<int>(601,1));
    for(int i = 0; i < N; i++) {
        vector<int>a(A[i]+1),b(B[i]+1);
        for(int j = 0; j <= A[i]; j++) {
            a[j] = COM(A[i],j);
        }
        for(int j = 0; j <= B[i]; j++) {
            b[j] = COM(B[i],j);
        }
        reverse(b.begin(),b.end());
        vector<int>c = convolution(a,b);
        vector<int>d(601);
        for(int j = 0; j <= A[i]+B[i]; j++) {
            d[300+j-B[i]] = c[j];
        }
        for(int j = 0; j <= 600; j++) {
            dp[i%M][j] = 1ll*dp[i%M][j]*d[j]%mod;
        }
    }
    vector<int>id(M);
    iota(id.begin(),id.end(),0);
    while(id.size() > 1) {
        vector<int>nxt;
        if(id.size()%2) {
            nxt.push_back(id.back());
        }
        for(int i = 0; i+1 < id.size(); i += 2) {
            dp[id[i]] = convolution(dp[id[i]],dp[id[i+1]]);
            if(dp[id[i]].size() > 300*M+1) {
                dp[id[i]].resize(300*M+1);
            }
            nxt.push_back(id[i]);
        }
        id = nxt;
    }
    cout << dp[id[0]][300*M] << endl;
}
0