Submission #3188018
Source Code Expand
#include<bits/stdc++.h> #define gc getchar() #define ll long long #define pb push_back #define mk make_pair #define rint register int using namespace std; const int mod = 1e9+7; inline int read(){char ch=gc;int w=1,s=0;while(!isdigit(ch)){if(ch=='-') w=-1;ch=gc;};while(isdigit(ch)){s=s*10+ch-'0';ch=gc;} return w*s;} int A[100010],n,m,fac[2000010],Ifac[2000010]; int f[18][1<<17]; inline int C(int p,int q) { return 1ll*fac[p]*Ifac[q]%mod*Ifac[p-q]%mod; } inline ll ksm(ll x,ll y){ll res=1; while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;} inline void Init() { Ifac[0]=1;fac[0]=1; for(rint i=1;i<=2e6;++i) fac[i]=1ll*fac[i-1]*i%mod; Ifac[2000000]=ksm(fac[2000000],mod-2); for(rint i=(2e6)-1;i;--i) Ifac[i]=1ll*Ifac[i+1]*(i+1)%mod; }inline bool cmp(int a,int b) {return a>b;} inline ll add(ll a,ll b){a+=b;if(a>=mod) a-=mod;return a;} int main() { n=read(),m=read(); for(rint i=1;i<=m;++i) A[i]=read(); sort(A+1,A+m+1,cmp);Init(); f[0][0]=1;int Max=1<<n; for(rint i=1;i<=m;++i) { for(rint j=0;j<Max;++j) f[i][j]=add(f[i][j],f[i-1][j]); for(rint j=0;j<Max;++j) { // int total=0; // for(rint k=1;k<=n;++k) // { // if((1<<k-1)&j) total+=(1<<k-1); // } int rest=(1<<n)-j-A[i]; for(rint k=1;k<=n;++k) { if((1<<k-1)&j) continue; else { if((1<<k-1)-1>rest) continue; f[i][j|(1<<k-1)]=add(f[i][j|(1<<k-1)],1ll*f[i-1][j]*C(rest,(1<<k-1)-1)%mod*fac[1<<k-1]%mod); } } } }ll res=0; for(rint i=0;i<Max;++i) { // cout<<f[m][i]<<"\n"; int cnt=__builtin_popcount(i); if(cnt&1) { res=add(res,mod-1ll*f[m][i]*fac[ksm(2,n)-i-1]%mod); } else res=add(res,1ll*f[m][i]*fac[ksm(2,n)-i-1]%mod); }cout<<1ll*res*ksm(2,n)%mod<<"\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Dark Horse |
User | was_n |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 1780 Byte |
Status | AC |
Exec Time | 147 ms |
Memory | 23808 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1100 / 1100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 36 ms | 23168 KB |
02.txt | AC | 117 ms | 23808 KB |
03.txt | AC | 118 ms | 23808 KB |
04.txt | AC | 116 ms | 23808 KB |
05.txt | AC | 87 ms | 21760 KB |
06.txt | AC | 101 ms | 23808 KB |
07.txt | AC | 112 ms | 23808 KB |
08.txt | AC | 123 ms | 23808 KB |
09.txt | AC | 133 ms | 23808 KB |
10.txt | AC | 123 ms | 23808 KB |
11.txt | AC | 28 ms | 16896 KB |
12.txt | AC | 36 ms | 17152 KB |
13.txt | AC | 45 ms | 17664 KB |
14.txt | AC | 52 ms | 19712 KB |
15.txt | AC | 27 ms | 16896 KB |
16.txt | AC | 27 ms | 18944 KB |
17.txt | AC | 27 ms | 18944 KB |
18.txt | AC | 27 ms | 20992 KB |
19.txt | AC | 27 ms | 18944 KB |
20.txt | AC | 28 ms | 23040 KB |
21.txt | AC | 140 ms | 23808 KB |
22.txt | AC | 128 ms | 23808 KB |
23.txt | AC | 111 ms | 23808 KB |
24.txt | AC | 90 ms | 23808 KB |
25.txt | AC | 100 ms | 21760 KB |
26.txt | AC | 70 ms | 19712 KB |
27.txt | AC | 28 ms | 20992 KB |
28.txt | AC | 27 ms | 16896 KB |
29.txt | AC | 27 ms | 20992 KB |
30.txt | AC | 27 ms | 18944 KB |
31.txt | AC | 28 ms | 23040 KB |
32.txt | AC | 147 ms | 23808 KB |
33.txt | AC | 27 ms | 16896 KB |
34.txt | AC | 27 ms | 18944 KB |
35.txt | AC | 27 ms | 20992 KB |
36.txt | AC | 28 ms | 23040 KB |
sample-01.txt | AC | 27 ms | 16896 KB |
sample-02.txt | AC | 27 ms | 16896 KB |
sample-03.txt | AC | 27 ms | 16896 KB |
sample-04.txt | AC | 27 ms | 16896 KB |
sample-05.txt | AC | 144 ms | 23808 KB |