/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Wrong Answer 2ms 504.0 KiB
#3 Wrong Answer 2ms 512.0 KiB
#4 Wrong Answer 2ms 540.0 KiB
#5 Wrong Answer 2ms 588.0 KiB
#6 Wrong Answer 3ms 612.0 KiB
#7 Wrong Answer 4ms 496.0 KiB
#8 Wrong Answer 3ms 496.0 KiB
#9 Wrong Answer 2ms 616.0 KiB
#10 Wrong Answer 2ms 544.0 KiB
#11 Accepted 2ms 512.0 KiB
#12 Wrong Answer 3ms 528.0 KiB
#13 Wrong Answer 2ms 496.0 KiB
#14 Wrong Answer 3ms 544.0 KiB
#15 Wrong Answer 4ms 468.0 KiB

Code

                                                  //   Bismillahir Rahmanir Rahim      //
                                                 //     After hardship comes ease     //
                                                //         AUTHOR : iamarman         //

// pragmas
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimization ("strict-overflow")
 
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>


using namespace std;
using namespace __gnu_pbds;

                                                    ////       TEMPLATE       ////

//---------------------------------------------------------------------------------------------------------------------------------|

typedef     vector<int> vii;
typedef     vector<long long> vll;
typedef     vector<pair<int,int> > vpi;
typedef     vector<pair<long long,long long > > vpl;

# define    el '\n'
# define    ff first
# define    ss second
# define    R0 return 0
# define    ll long long
# define    noo1 cout<<-1<<el;  
# define    ull unsigned long long                                                                                                         
# define    rep(i,a,b) for(int i=a;i<b;i++)
# define    rep_n(i,a,b) for(int i=a;i<=b;i++)
# define    test int test; cin>>test; while(test--)
# define    rep_rev(i,a,b) for(int i=b;a>=1;i--)
# define    allr(v) v.rbegin(),v.rend()
# define    all(v) v.begin(),v.end()
# define    yess cout<<"YES"<<el
# define    siz(x) (int)x.size()
# define    noo cout<<"NO"<<el
# define    yess1 cout<<1<<el
# define    pb push_back
# define    mp make_pair
# define    sp " "


 constexpr ll mod=1000000007;
constexpr ll INF=LLONG_MAX;
constexpr double PI= acos(-1);
constexpr double eps=1e-9;

# define mem(a,b) memset(a,b,sizeof(a))
# define sqr(a) ((a)*(a))
# define lcm(a,b) (a*b)/__gcd(a,b)

# define optimise   { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
# define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield);
# define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

// find_by_order() - Returns an iterator to the k-th largest element (counting from zero)
// order_of_key()  - The number of items in a set that are strictly smaller than our item 
// greater instead of less for descending order
// less_equal works as ordered multiset
// we can use pair<int,int> instead of int for pair of orderd set
// for multiset st.lower_bound(x) works as upper bound and st.upper_bound(x) works as lower bound

inline void file() {
#ifndef ONLINE_JUDGE  
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

//----------------------------------------------------------------------------------------------------------------------------------|



                                                               // DEBUGGER //


//----------------------------------------------------------------------------------------------------------------------------------|

template < typename F, typename S > ostream& operator << ( ostream& os, const pair< F, S > & p ) { return os << "(" << p.first << ", " << p.second << ")"; }
template < typename T > ostream &operator << ( ostream & os, const vector< T > &v ) { os << "{"; for(auto it = v.begin(); it != v.end(); ++it) { if( it != v.begin() ) os << ", ";  os << *it; }  return os << "}";  }
template < typename T >  ostream &operator << ( ostream & os, const set< T > &v ) { os << "["; for(auto it = v.begin(); it != v.end(); ++it) { if( it != v.begin() ) os << ", "; os << *it;  } return os << "]"; }
template < typename T > ostream &operator << ( ostream & os, const multiset< T > &v ) { os << "["; for(auto it = v.begin(); it != v.end(); ++it) { if( it != v.begin() ) os << ", "; os << *it; } return os << "]"; }
template < typename F, typename S > ostream &operator << ( ostream & os, const map< F, S > &v ) { os << "["; for(auto it = v.begin(); it != v.end(); ++it) { if( it != v.begin() ) os << ", "; os << it -> first << " = " << it -> second ; } return os << "]";  }
#define dbg(args...) do {cerr << #args << " : "; iamarman(args); } while(0)
void iamarman () { cerr << endl; }
template <typename T> void iamarman( T a[], int n ) {   for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl;  }
template <typename T, typename ... hello>  void iamarman( T arg, const hello &... rest) {   cerr << arg << ' ';  iamarman(rest...);  }

//--------------------------------------------------------------------------------------------------------------------------------------|



                                                           /////    FUNCTIONS     /////



ll bigmod(ll base,ll power,ll mod){ ll res=1; ll p=base%mod; while(power>0) { if(power%2==1) {  res=((res%mod)*(p%mod))%mod; }  power/=2; p=((p%mod)*(p%mod))%mod; } return res; }

ll inversemod(ll base,ll mod) { return bigmod(base,mod-2,mod); }

ll poww(ull a,ull b) { ull ans=1; if(!b) return 1; while(b>1) {  if(b&1) { ans=ans*a%mod; } a=a*a%mod; b/=2; }return a*ans%mod; }

int gcd(ll a,ll b) { ll rem; while(b%a!=0)  {  rem=b%a;  b=a;  a=rem; } return a; }

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

 
int dx[]={-1, 1 , 0 , 0 , -1 ,-1, 1, 1};
int dy[]={ 0, 0 ,-1 , 1 , -1 , 1,-1, 1};

// up = { -1,0 } , down = { 1,0 } , right = { 0,1 } , left = { 0,-1 }
// up-right = { -1,1 } , up-left = { -1,-1 } , down-right = { 1,1 } , down-left = { 1,-1 }




                                                   ///  ____________CODE STARTS FROM HERE____________    ///


ll count(ll x, int i) {

    ll bit_mask = 1LL << i;
    ll full_cycles = (x + 1) / (bit_mask << 1);
    ll remainder = (x + 1) % (bit_mask << 1);

    return (full_cycles * bit_mask) + max(0LL, remainder - bit_mask);
}

bool comp(string a,string b)
{
    string c=a+b;
    string d=b+a;
    if(c<d) return true;
    return false;
}


vector<ll> fact(5005);
void pre()
{
    fact[0]=1;
    for(int i=1;i<5005;i++)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=mod;
    }
}

ll ncr(int n,int r)
{
    ll ans=fact[n]%mod;
    ans*=inversemod(fact[r],mod)%mod;
    ans*=inversemod(fact[n-r],mod)%mod;

    return ans;
}

void solve()
{   
    int n,k;
    cin>>n>>k;
    int one=0,zero=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        (x==1 ? one++ : zero++);
    }
    ll ans=0;

    for(int i=1;i<=one-k;i++)
    {
        ll cur=ncr(one,i);
        cur%=mod;
        ans+=cur;
        ans%=mod;

        ll x=bigmod(2,zero,mod);
        x--;
        ans+=x;
        x*=cur;
        x%=mod;
        ans+=x;
        
    }

    cout<<ans<<el;





}
int main() 
{ 
    optimise;
    //file();
    clock_t start= clock();
     pre();
    int t=1;
    cin>>t;

    for(int i=1;i<=t;i++)
    {
        //cout<<"Case #"<<i<<": "; 
        solve();
       
    } 
    cerr << "Run Time : " <<((double)(clock() - start) / CLOCKS_PER_SEC)<<el;

}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-13 20:12:10
Judged At
2024-09-13 20:12:10
Judged By
Score
11
Total Time
4ms
Peak Memory
768.0 KiB