/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 480.0 KiB
#4 Accepted 2ms 536.0 KiB
#5 Accepted 2ms 580.0 KiB
#6 Accepted 2ms 576.0 KiB
#7 Accepted 3ms 536.0 KiB
#8 Accepted 3ms 652.0 KiB
#9 Accepted 2ms 540.0 KiB
#10 Accepted 2ms 532.0 KiB
#11 Accepted 2ms 344.0 KiB
#12 Accepted 2ms 580.0 KiB
#13 Accepted 2ms 580.0 KiB
#14 Accepted 2ms 576.0 KiB
#15 Accepted 3ms 576.0 KiB
#16 Accepted 16ms 764.0 KiB
#17 Accepted 24ms 1.469 MiB
#18 Accepted 33ms 2.176 MiB
#19 Accepted 49ms 3.625 MiB
#20 Accepted 14ms 564.0 KiB
#21 Accepted 23ms 1.531 MiB

Code

#include <bits/stdc++.h>

#ifdef LOCAL
#include "template.cpp.h"
#else
#define debug(...)
#endif

#define int long long
using namespace std;
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

template<int MOD>
class ModNum {
    int val;

public:
    ModNum(int val_ = 0) : val(val_ % MOD) {}

    operator int() const { return val; }

    ModNum pow(int p) const {
        ModNum res = 1;
        for (ModNum base = val; p > 0; p >>= 1, base *= base)
            if (p & 1LL) res *= base;
        return res;
    }

    ModNum inv() const {
        static_assert(MOD >= 2);
        assert (val != 0);
        return pow(MOD - 2);
    }

    ModNum operator+(const ModNum &other) const { return (val + other.val) % MOD; }

    ModNum operator-(const ModNum &other) const { return (val + MOD - other.val) % MOD; }

    ModNum operator*(const ModNum &other) const { return (val * other.val) % MOD; }

    ModNum operator/(const ModNum &other) const { return (*this) * other.inv(); }

    ModNum &operator+=(const ModNum &other) { return *this = *this + other; }

    ModNum &operator-=(const ModNum &other) { return *this = *this - other; }

    ModNum &operator*=(const ModNum &other) { return *this = *this * other; }

    ModNum &operator/=(const ModNum &other) { return *this = *this / other; }

    bool operator==(const ModNum &other) const { return val == other.val; }


    friend ModNum operator+(int a, const ModNum &b) { return ModNum(a) + b; }

    friend ModNum operator-(int a, const ModNum &b) { return ModNum(a) - b; }

    friend ModNum operator*(int a, const ModNum &b) { return ModNum(a) * b; }

    friend ModNum operator/(int a, const ModNum &b) { return ModNum(a) / b; }

    friend bool operator==(int a, const ModNum &b) { return ModNum(a) == b; }

    friend ostream &operator<<(ostream &os, const ModNum &num) { return os << num.val; }

    friend istream &operator>>(istream &is, ModNum &num) { return is >> num.val; }
};

const int P = 1e9 + 7;
using mint = ModNum<P>;

//fact
vector<mint> fact(1, 1);
vector<mint> inv_fact(1, 1);

mint C(int n, int k) {
    if (k < 0 || k > n) return 0;
    while (fact.size() < n + 1) {
        fact.push_back(fact.back() * (mint) fact.size());
        inv_fact.push_back(mint(1) / fact.back());
    }
    return fact[n] * inv_fact[k] * inv_fact[n - k];
}

void shelby() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(2);
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        cnt[x] += 1;
    }
    mint ans = 0, mul = mint(2).pow(cnt[0]);
    for (int i = k; i <= cnt[1]; ++i) ans += C(cnt[1], i) * (mul - mint(i == cnt[1]));
    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->ios_base::sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
//        cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-06 11:03:05
Judged At
2024-11-11 02:56:23
Judged By
Score
100
Total Time
49ms
Peak Memory
3.625 MiB