/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 110ms 76.953 MiB
#2 Accepted 111ms 76.797 MiB
#3 Accepted 110ms 76.887 MiB
#4 Accepted 110ms 76.977 MiB
#5 Accepted 110ms 76.941 MiB
#6 Accepted 109ms 76.949 MiB
#7 Accepted 108ms 76.887 MiB
#8 Accepted 109ms 76.848 MiB
#9 Accepted 108ms 76.816 MiB
#10 Accepted 109ms 76.988 MiB
#11 Accepted 107ms 76.988 MiB
#12 Accepted 107ms 76.906 MiB
#13 Accepted 109ms 77.027 MiB
#14 Accepted 110ms 76.816 MiB
#15 Accepted 110ms 76.867 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
P1093 Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 18:23:09
Judged At
2024-11-11 02:45:11
Judged By
Score
100
Total Time
111ms
Peak Memory
77.027 MiB