QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#144251#6134. Soldier Gamesihan_88WA 2ms3880kbC++141005b2023-08-21 16:02:062023-08-21 16:03:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-21 16:03:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3880kb
  • [2023-08-21 16:02:06]
  • 提交

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'