/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 3.52 MiB
#2 Accepted 5ms 3.52 MiB
#3 Accepted 6ms 3.52 MiB
#4 Accepted 7ms 3.445 MiB
#5 Accepted 9ms 3.625 MiB
#6 Accepted 9ms 3.52 MiB
#7 Accepted 9ms 3.512 MiB
#8 Accepted 9ms 3.539 MiB
#9 Accepted 9ms 3.523 MiB
#10 Accepted 9ms 3.52 MiB
#11 Accepted 9ms 3.52 MiB
#12 Accepted 9ms 3.57 MiB
#13 Accepted 9ms 3.566 MiB
#14 Accepted 12ms 3.469 MiB
#15 Accepted 13ms 3.43 MiB
#16 Accepted 40ms 3.691 MiB
#17 Accepted 18ms 4.148 MiB
#18 Accepted 19ms 5.074 MiB
#19 Accepted 17ms 5.02 MiB
#20 Accepted 18ms 5.039 MiB
#21 Accepted 18ms 4.27 MiB

Code


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n';

const int N = 2e5 + 9, mod = 1e9 + 7;

long long binmul(long long a, long long b)
{
   return ((a % mod) * (b % mod)) % mod;
}
long long binpow(long long a, long long b)
{
   a %= mod;
   long long res = 1LL;
   while (b > 0)
   {
      if (b & 1)
         res = binmul(res, a);
      a = binmul(a, a);
      b >>= 1;
   }
   return res;
}
long long inverse(long long a)
{
   return binpow(a, mod - 2);
}

int power(long long n, long long k)
{
   int ans = 1 % mod;
   n %= mod;
   if (n < 0)
      n += mod;
   while (k)
   {
      if (k & 1)
         ans = (long long)ans * n % mod;
      n = (long long)n * n % mod;
      k >>= 1;
   }
   return ans;
}
int f[N], invf[N];
void pre_call()
{
   f[0] = 1;
   for (int i = 1; i < N; i++)
   {
      f[i] = 1LL * i * f[i - 1] % mod;
   }
   invf[N - 1] = power(f[N - 1], mod - 2);
   for (int i = N - 2; i >= 0; i--)
   {
      invf[i] = 1LL * invf[i + 1] * (i + 1) % mod;
   }
}
int nCr(int n, int r)
{
   if (n < r or n < 0)
      return 0;
   if (r < 0)
      return 1;
   return 1LL * f[n] * invf[r] % mod * invf[n - r] % mod;
}
int nPr(int n, int r)
{
   if (n < r or n < 0)
      return 1;
   return 1LL * f[n] * invf[n - r] % mod;
}

int minuss(int a, int b)
{
   a %= mod;
   b %= mod;

   a += mod;
   a -= b;

   a %= mod;

   return a;
}

int ar[N + 3];
int n, k;

int rec(int i, int sm)
{
   if (i == n + 1)
   {
      return sm >= k;
   }

   int ans = 0;
   ans += rec(i + 1, sm);
   ans += rec(i + 1, sm - ar[i]);

   return ans;
}

void solve()
{

   cin >> n >> k;

   int one = 0, zero = 0;
   for (int i = 1; i <= n; i++)
   {
      cin >> ar[i];
      if (ar[i] == 1)
      {
         one++;
      }
      else
         zero++;
   }
   // cout << "rec ans = " << rec(1, one) - 1 << endl;

   if (k > one)
   {
      cout << 0 << endl;
      return;
   }
   else
   {
      int x = 0;
      for (int i = k; k <= one; k++)
      {
         x += nCr(one, k);
      }

      x = binmul(binpow(2, zero), x);
      x = minuss(x, 1);
      cout << x << endl;
   }
}
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t = 1;
   pre_call();
   cin >> t;
   while (t--)
      solve();
   return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-08 14:41:21
Judged At
2024-09-08 14:41:21
Judged By
Score
100
Total Time
40ms
Peak Memory
5.074 MiB