QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632075#9451. Expected Waiting Timeucup-team2279#WA 573ms34644kbC++20836b2024-10-12 11:52:572024-10-12 11:52:58

Judging History

This is the latest submission verdict.

  • [2024-10-12 11:52:58]
  • Judged
  • Verdict: WA
  • Time: 573ms
  • Memory: 34644kb
  • [2024-10-12 11:52:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
void solve(){
	int n,mod,A,B,ans=0;
	cin>>n>>mod;
	vector<int> b(n*2+1),a(n*2+1),iv(n+2),c(n+1),f(n*2+1);
	cin>>b[0]>>A>>B;
	for(int i=1;i<=n*2;i++) b[i]=(1ll*A*b[i-1]+B)%mod,a[i]=(a[i-1]+b[i]+1)%mod;
	iv[1]=1;c[0]=c[1]=1;
	for(int i=2;i<=n+1;i++) iv[i]=1ll*(mod-mod/i)*iv[mod%i]%mod;
	for(int i=2;i<=n;i++) c[i]=(4ll*i-2)*iv[i+1]%mod*c[i-1]%mod;
	for(int i=2;i<=n*2;i++){
		int t=i/2-1;
		f[i]=(f[i-2]+1ll*c[t]*c[n-t-1])%mod;
	}
	for(int i=1;i<=n*2;i++){
		if(i>1) (ans+=1ll*a[i]*f[i]%mod)%=mod;
		if(i<n*2) (ans+=mod-1ll*a[i]*f[n*2-i+1]%mod)%=mod;
	}
	for(int x=c[n],y=mod-2;y;y>>=1,x=1ll*x*x%mod) if(y&1) ans=1ll*ans*x%mod;
	cout<<ans<<"\n";
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3852kb

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: 547ms
memory: 3848kb

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: 573ms
memory: 34644kb

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:

915203602
1336295853
1233624411
827110887
1113358375
115525157
-750714488
-699840795
1573003141
-847451499
1009499206
323594287
525702127
-1634746813
638792143
1057681953
159869961
562627301
158902545
1000840323
121482026
528971898
-1065380726
239616933
558752169
1050819260
-965259155
844160548
3297...

result:

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