/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 75ms 76.914 MiB
#2 Wrong Answer 74ms 76.816 MiB
#3 Wrong Answer 75ms 76.816 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]) 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:20:28
Judged At
2024-11-11 02:45:11
Judged By
Score
1
Total Time
75ms
Peak Memory
76.914 MiB