QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#144251 | #6134. Soldier Game | sihan_88 | WA | 2ms | 3880kb | C++14 | 1005b | 2023-08-21 16:02:06 | 2023-08-21 16:03:50 |
Judging History
answer
#include<cstdio>
typedef long long ll;
const int MOD=int(1e9)+7;
const int INV2=(MOD+1)>>1;
inline ll ksm(ll b,int p)
{
ll res=1;
for(;p;p>>=1,b=b*b%MOD) if(p&1) (res*=b)%=MOD;
return res;
}
const int N=100010;
ll fact[N],fact_inv[N],P[N];
inline ll C(int n,int m)
{
if(n<0||m<0||n<m) return 0;
return fact[n]*fact_inv[m]%MOD*fact_inv[n-m]%MOD;
}
inline ll F(int n,int m)
{
//a_i\ge2 \sum_{a_i}=n
if(!m) return n==0;
return C(n-m-1,m-1);
}
int main()
{
fact[0]=P[0]=1;
for(int i=1;i<N;++i) fact[i]=fact[i-1]*i%MOD,P[i]=P[i-1]*INV2%MOD;
fact_inv[N-1]=ksm(fact[N-1],MOD-2);
for(int i=N-2;i>=0;--i) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
int T,n;
ll m;
scanf("%d",&T);
while(T--)
{
scanf("%d%lld",&n,&m);
if(m>n) puts("0");
else if(m==n) printf("%lld\n",fact[n-1]*INV2%MOD);
else
{
ll sum=0;
for(int i=0;i<=n-m;++i) sum=(sum+C(n-m,i)*P[i]%MOD*F(m+i,i))%MOD;
printf("%lld\n",sum*fact[n]%MOD*fact_inv[n-m]%MOD);
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3880kb
input:
3 5 -1 4 2 1 1 4 1 3 2 4 1 7
output:
0 15 500000004
result:
wrong answer 1st numbers differ - expected: '1', found: '0'