Submission #28865352


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define trav(u, x) for (auto &u : x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

using namespace atcoder;
using mint = modint998244353;

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);

    rep(i, 0, n) cin >> a[i];
    rep(i, 1, n) a[0] -= a[i];
    if(a[0]<k) {
        cout << "0\n";
        return;
    }

    mint inv = 1;
    rep(i, 1, k) inv *= mint(i).inv();

    auto binom = [&](mint n) {
        mint res = inv;
        rep(i, 0, k-1) res *= n-i;
        return res;
    };

    mint res = binom(a[0]-1);
    rep(i, 1, n) res *= binom(a[i]+k-1);
    cout << res.val() << "\n"; 
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    solve();
}

Submission Info

Submission Time
Task C - The Majority
User zdolna_kaczka
Language C++ (GCC 9.2.1)
Score 500
Code Size 966 Byte
Status AC
Exec Time 90 ms
Memory 4032 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 33
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 14 ms 3680 KiB
random_02.txt AC 14 ms 4032 KiB
random_03.txt AC 2 ms 3540 KiB
random_04.txt AC 85 ms 4012 KiB
random_05.txt AC 2 ms 3552 KiB
random_06.txt AC 16 ms 3976 KiB
random_07.txt AC 2 ms 3540 KiB
random_08.txt AC 89 ms 3932 KiB
random_09.txt AC 2 ms 3612 KiB
random_10.txt AC 13 ms 3932 KiB
random_11.txt AC 3 ms 3604 KiB
random_12.txt AC 90 ms 3968 KiB
random_13.txt AC 77 ms 3912 KiB
random_14.txt AC 22 ms 3712 KiB
random_15.txt AC 49 ms 3700 KiB
random_16.txt AC 40 ms 3740 KiB
random_17.txt AC 33 ms 3932 KiB
random_18.txt AC 41 ms 3648 KiB
random_19.txt AC 61 ms 3880 KiB
random_20.txt AC 4 ms 3712 KiB
random_21.txt AC 23 ms 3620 KiB
random_22.txt AC 9 ms 3604 KiB
random_23.txt AC 15 ms 3700 KiB
random_24.txt AC 36 ms 3556 KiB
random_25.txt AC 7 ms 3628 KiB
random_26.txt AC 11 ms 3612 KiB
random_27.txt AC 7 ms 3628 KiB
random_28.txt AC 17 ms 3616 KiB
random_29.txt AC 13 ms 4032 KiB
random_30.txt AC 13 ms 3680 KiB
sample_01.txt AC 2 ms 3640 KiB
sample_02.txt AC 2 ms 3624 KiB
sample_03.txt AC 2 ms 3696 KiB