QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292824#7662. Kaldorian Knightshy233WA 12ms20460kbC++141007b2023-12-28 14:27:382023-12-28 14:27:39

Judging History

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

  • [2023-12-28 14:27:39]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:20460kb
  • [2023-12-28 14:27:38]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
const ll mod=1e9+7;
inline int rd()
{
    int x=0; bool f=1;
    char ch=getchar();
    for(;!isdigit(ch);ch=getchar())
        if(ch=='-') f=0;
    for(;isdigit(ch);ch=getchar())
        x=x*10+(ch^48);
    return f?x:-x;
}
ll fp(ll a,ll b=mod-2)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)
			ans=ans*a%mod;
	return ans;
}
ll fac[N],ifac[N];
void init(int n)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%mod;
	ifac[n]=fp(fac[n]);
	for(int i=n;i;i--)
		ifac[i-1]=ifac[i]*i%mod;
}
inline ll C(int n,int m)
{ return fac[n]*ifac[m]%mod*ifac[n-m]%mod; } 
int a[N];
ll d[N];
int main()
{
	init(1e6);
	int n=rd(),h=rd();
	for(int i=1;i<=h;i++)
		a[i]=rd()+a[i-1];
	ll ans=fac[n];
	for(int i=1;i<=h;i++)
		d[i]=(fac[a[i]]+mod-d[i-1]*fac[a[i]-a[i-1]]%mod)%mod;
	for(int i=1;i<=h;i++)
		ans=(ans+mod-d[i]*fac[n-a[i]]%mod)%mod;
	cout<<ans<<endl;
	
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 19600kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 0ms
memory: 19320kb

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 12ms
memory: 19800kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 8ms
memory: 20460kb

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 4ms
memory: 19312kb

input:

10 10
1
1
1
1
1
1
1
1
1
1

output:

999432627

result:

wrong answer 1st lines differ - expected: '0', found: '999432627'