/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'void solve()':
foo.cc:48:5: error: 'vector' was not declared in this scope
   48 |     vector<int>p(n);
      |     ^~~~~~
foo.cc:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
foo.cc:48:12: error: expected primary-expression before 'int'
   48 |     vector<int>p(n);
      |            ^~~
foo.cc:52:16: error: 'p' was not declared in this scope
   52 |         cin >> p[i];
      |                ^

Code

#include <iostream>
using namespace std;
#define MOD 1000000007
#define ll long long
ll mod = 1e9+7;
const int MAX = 1e5 + 5;
ll fact[MAX];

// Precompute factorials
void computeFactorials() {
    fact[0] = 1;
    for (int i = 1; i < MAX; ++i)
        fact[i] = (fact[i - 1] * i) % MOD;
}

// Binary exponentiation for modular inverse
ll modInverse(ll a, ll m = MOD) {
    ll res = 1;
    ll b = m - 2;
    while (b) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}
long long modPow(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
ll nCr(int n, int r) {
    if (r > n) return 0;
    return fact[n] * modInverse(fact[r]) % MOD * modInverse(fact[n - r]) % MOD;
}

ll nPr(int n, int r) {
    if (r > n) return 0;
    return fact[n] * modInverse(fact[n - r]) % MOD;
}
void solve(){
    ll ans = 0;
    ll n,k;cin >> n>>k;
    vector<int>p(n);
    ll one = 0;
    ll zero = 0;
    for(int i = 0; i < n ; i++){
        cin >> p[i];
        if(p[i] == 0) zero++;
        else one++;
    }
    ll nts = modPow(2,zero);
    for(int i = k; i <= one ; i++){
        ans += (nCr(one,one-i)*nts);

    }
    cout << ans-1 << endl; 
}

int main() {
    computeFactorials();
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1093 E1.Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-08 09:47:26
Judged At
2025-08-08 09:47:26
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes