QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#636429 | #9451. Expected Waiting Time | ucup-team191# | WA | 583ms | 47308kb | C++23 | 1.4kb | 2024-10-12 23:51:27 | 2024-10-12 23:51:31 |
Judging History
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(int a,int 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;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9824kb
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: 559ms
memory: 9948kb
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: 583ms
memory: 47308kb
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:
1490941393 129062325 -159190335 827110887 606914000 -9959890 1181280931 -723246885 147889160 610896236 718756562 15404448 -1076829056 -336010379 -1825300727 -123247777 -1226528583 -37767675 -956393279 68739451 866566393 475728573 -275622319 -90383656 558752169 1050819260 641459034 844160548 -5888901...
result:
wrong answer 1st numbers differ - expected: '1532578211', found: '1490941393'