/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 628.0 KiB
#3 Wrong Answer 2ms 532.0 KiB
#4 Wrong Answer 2ms 532.0 KiB
#5 Accepted 2ms 536.0 KiB
#6 Accepted 2ms 592.0 KiB
#7 Accepted 2ms 576.0 KiB
#8 Accepted 2ms 480.0 KiB
#9 Accepted 2ms 640.0 KiB
#10 Wrong Answer 2ms 644.0 KiB
#11 Accepted 2ms 504.0 KiB
#12 Wrong Answer 2ms 484.0 KiB
#13 Wrong Answer 2ms 580.0 KiB
#14 Wrong Answer 2ms 572.0 KiB
#15 Accepted 2ms 532.0 KiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

const int mod = 1e9 + 7, MAX = 5005;

vector<long long> fact(MAX + 1), inv_fact(MAX + 1);

long long power(long long a, long long b) { // (a ^ b) % mod
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
void prec() {
    fact[0] = 1;
    for (int i = 1; i <= MAX; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
    inv_fact[MAX] = power(fact[MAX], mod - 2);
    for (int i = MAX - 1; i >= 0; i--) {
        inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod;
    }
}
long long nCr(int n, int r) {
    if (r > n || r < 0) return 0;
    return fact[n] * inv_fact[r] % mod * inv_fact[n - r] % mod;
}

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    prec();
    Too_Many_Jobs {
        int n, k;
        cin >> n >> k;
        int one = 0, zero = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            x ? one++ : zero++;
        }
        if (one < k) {
            cout << 0 << endl;
        } else {
            int all = power(2, n) - 1;
            int inv = 0;
            for (int i = 0; i < k; i++) {
                inv = (inv + (one ? nCr(one, i) : 0) + (zero ? nCr(zero, i) : 0)) % mod;
            }
            int ans = (all - inv + mod) % mod;
            cout << ans << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-06 16:55:21
Judged At
2024-09-06 16:55:21
Judged By
Score
60
Total Time
2ms
Peak Memory
644.0 KiB