/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 110ms 76.844 MiB
#2 Accepted 109ms 76.953 MiB
#3 Accepted 110ms 76.934 MiB
#4 Accepted 109ms 76.988 MiB
#5 Accepted 109ms 76.84 MiB
#6 Accepted 107ms 76.766 MiB
#7 Accepted 112ms 76.992 MiB
#8 Accepted 109ms 76.992 MiB
#9 Accepted 107ms 76.992 MiB
#10 Accepted 110ms 76.992 MiB
#11 Accepted 108ms 76.992 MiB
#12 Accepted 110ms 76.988 MiB
#13 Accepted 110ms 76.992 MiB
#14 Accepted 112ms 76.984 MiB
#15 Accepted 110ms 76.988 MiB
#16 Accepted 141ms 76.988 MiB
#17 Accepted 140ms 77.738 MiB
#18 Accepted 145ms 78.523 MiB
#19 Accepted 152ms 78.523 MiB
#20 Accepted 125ms 78.488 MiB
#21 Accepted 143ms 77.738 MiB

Code

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

const i64 mod = 1e9 + 7;
const i64 maxn = 1e7;

struct mi {
    i64 v;
    explicit operator i64() const { return v; }
    mi() { v = 0; }
    mi(long long x) : v(x % mod) { v += (v < 0) * mod; }
};

mi& operator+=(mi& a, mi b) {
    if ((a.v += b.v) >= mod) a.v -= mod;
    return a;
}

mi& operator-=(mi& a, mi b) {
    if ((a.v -= b.v) < 0) a.v += mod;
    return a;
}

mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((long long)a.v * b.v); }
mi& operator*=(mi& a, mi b) { return a = a * b; }

mi pw(mi a, long long p) {
    mi res = 1;
    while (p > 0) {
        if (p & 1) res *= a;
        a *= a;
        p >>= 1;
    }
    return res;
}

mi inv(mi a) {
    return pw(a, mod - 2);
}
mi operator/(mi a, mi b) { return a * inv(b); }

vector<mi> fct(maxn + 1, 1);

void prefact() {
    for (i64 i = 2; i <= maxn; ++i)
        fct[i] = fct[i - 1] * i;
}

mi ncr(i64 n, i64 r) {
    if (r < 0 or r > n) return 0;
    return fct[n] * inv(fct[r] * fct[n - r]);
}

void solve() {
    i64 n, k; cin >> n >> k;
    vector<i64> f (2);
    vector<i64> a (n); for (i64 i = 0; i < n; ++i) cin >> a[i], ++f[a[i]];

    mi ans = 0;
    for (i64 i = k; i < f[1]; ++i) {
        ans += ncr(f[1], i) * pw(2, f[0]);
    }
    if (f[0] and f[1] >= k) ans += pw(2, f[0]) - 1;
    cout << i64(ans) << '\n';
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    prefact();
    i64 T; cin >> T;
    while(T--) solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 18:22:33
Judged At
2024-11-11 02:45:11
Judged By
Score
100
Total Time
152ms
Peak Memory
78.523 MiB