QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#636434#9451. Expected Waiting Timeucup-team191#WA 616ms52916kbC++231.4kb2024-10-12 23:53:122024-10-12 23:53:13

Judging History

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

  • [2024-10-12 23:53:13]
  • 评测
  • 测评结果:WA
  • 用时:616ms
  • 内存:52916kb
  • [2024-10-12 23:53:12]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using pii=pair<int,int>;
#define all(a) begin(a),end(a)
#define pb push_back

const int N=10000010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int t,n,p,b0,A,B,fac[N],inf[N],a[N],b[N],ps[N],cat[N];

int mul(int a,int b,int p)
{
	return (a*1ll*b)%p;
}

int add(ll a,ll b,int p)
{
	if (a+b>=p) return a+b-p;
	return a+b;
}

int sub(int a,int b,int p)
{
	if (a<b) return a-b+p;
	return a-b;
}

int pot(int n,int k,int p)
{
	if (k==0) return 1;
	int r=pot(n,k/2,p);
	r=mul(r,r,p);
	if (k%2) r=mul(r,n,p);
	return r;
}

int cho(int a,int b,int p)
{
	if (b>a || b<0) return 0;
	return mul(fac[a],mul(inf[b],inf[a-b],p),p);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while (t--)
	{
		cin>>n>>p>>b0>>A>>B;
		fac[0]=1;
		for (int i=1;i<=2*n;++i) fac[i]=mul(fac[i-1],i,p);
		inf[2*n]=pot(fac[2*n],p-2,p);
		for (int i=2*n-1;i>=0;--i) inf[i]=mul(inf[i+1],i+1,p);
		for (int i=0;i<=n;++i) cat[i]=sub(cho(2*i,i,p),cho(2*i,i-1,p),p);
		for (int i=1;i<=n;++i) ps[i]=add(ps[i-1],mul(cat[i-1],cat[n-i],p),p);
		b[0]=b0;
		int an=0;
		for (int i=1;i<=2*n;++i)
		{
			b[i]=add(mul(A,b[i-1],p),B,p);
			a[i]=add(add(a[i-1],b[i],p),1,p);
			an=add(an,mul(a[i],sub(2*ps[i/2],ps[n],p),p),p);
		}
		cout<<mul(an,pot(ps[n],p-2,p),p)<<en;
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9872kb

input:

5
1 1000000007 0 1 0
2 1000000007 0 1 1
2 7 5 2 3
3 31 15 6 24
20 1000000007 0 1 0

output:

1
12
1
21
879705565

result:

ok 5 number(s): "1 12 1 21 879705565"

Test #2:

score: 0
Accepted
time: 545ms
memory: 9820kb

input:

4400
3954 1000000007 0 1 0
1306 1000000007 0 1 0
3774 1000000007 0 1 0
3345 1000000007 0 1 0
891 1000000007 0 1 0
2462 1000000007 0 1 0
237 1000000007 0 1 0
26 1000000007 0 1 0
2510 1000000007 0 1 0
637 1000000007 0 1 0
3250 1000000007 0 1 0
3447 1000000007 0 1 0
1222 1000000007 0 1 0
133 1000000007...

output:

440618338
378292891
979368645
915766295
343598158
80867595
161627927
517387931
396936703
42785642
945720545
764273281
186237656
635777911
164064906
548455037
991964184
468137124
561243246
118562285
856945294
642467240
23673926
808943705
897417615
462422554
656411244
204288121
997894281
244685651
762...

result:

ok 4400 numbers

Test #3:

score: -100
Wrong Answer
time: 616ms
memory: 52916kb

input:

1019
338 1863833207 1820742817 1507924477 1822273457
770 1386304741 1088481071 1216187083 170973217
597 1604266739 620750027 196415899 456280997
105 1008587891 184044403 24836083 926135599
357 1165127407 440925347 1103369747 912263123
82 1639766993 263045351 631010551 1412721139
928 1715915153 25383...

output:

-1443705281
-425848074
-461801002
827110887
809798330
220043509
764868402
1440204499
-547642763
1023912577
498775116
608645852
57551464
1441082990
1672987991
1351967798
287110196
396746197
389091894
-241719521
438458110
-262954030
1597272358
-1141754774
558752169
1050819260
-1527743439
844160548
963...

result:

wrong answer 1st numbers differ - expected: '1532578211', found: '-1443705281'