Submission #851898

#TimeUsernameProblemLanguageResultExecution timeMemory
851898vjudge1Magneti (COCI21_magneti)C++17
30 / 110
1055 ms848 KiB
#ifndef Local #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #endif #include <bits/stdc++.h> #define int long long #define pb push_back #define lim 1000000 #define till 1000001 // # of primes till 1e6 = 7e4 using namespace std; using pii = array<int,2>; const int mod=1000000007ll; void mul(int*a,int b){ *a=((*a%mod)*(b%mod)); } int mul(int a,int b){ return ((a%mod)*(b%mod))%mod; } int expo(int a,int b){ int ans=1; while(b){ if(b&1){ mul(&ans,a); } mul(&a,a); b>>=1; } return ans; } int fact[20001]; int divy[20001]; int comb(int a,int b){ return mul(mul(fact[a],divy[b]),divy[a-b]); } void solve(){ int n,l; cin>>n>>l; fact[0]=1; divy[0]=1; for(int i=1;i<20001;i++){ fact[i]=mul(fact[i-1],i); divy[i]=expo(fact[i],mod-2); } int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); if(a[0]==a[n-1]){ if(a[0]*(n-1)+1>l){ cout<<"0\n"; return; } cout<<mul(fact[n],comb(l-a[0]*(n-1)-1+n,n)); }else{ pair<int,int> b[n]; for(int i=0;i<n;i++){ b[i]={a[i],i}; } sort(b,b+n); int ans=0; do{ int sums=l-1; for(int i=0;i<n-1;i++){ sums-=max(b[i].first,b[i+1].first); if(sums<0)goto wow; } /* for(pii k:b){ cerr<<k[0]<<" "; }cerr<<"\n"; cerr<<sums<<"\n"; */ ans+=comb(sums+n,n); ans%=mod; wow:; }while(next_permutation(b,b+n)); cout<<ans<<"\n"; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif int t=1; //cin>>t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...