QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632583 | #9451. Expected Waiting Time | ucup-team1004# | WA | 891ms | 50748kb | C++17 | 1.4kb | 2024-10-12 13:36:44 | 2024-10-12 13:36:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2e6+10;
int mod;
ll qpow(ll x,ll y=mod-2,ll ans=1){
for(;y;(x*=x)%=mod,y>>=1)if(y&1)(ans*=x)%=mod;
return ans;
}
int fac[N],ifac[N];
int C(int n,int m){
if(0>m||m>n)return 0;
return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
void init(int n){
for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
ifac[n]=qpow(fac[n]);
for(int i=n;i>=1;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
}
int calc(int x,int y){
return (C(x+y,x)-C(x+y,x+1)+mod)%mod;
}
int T,n,A,B,b[N],w[N];
ll a[N];
void get(){
scanf("%d%d%d%d%d",&n,&mod,&b[0],&A,&B),init(n+n);
for(int i=1;i<=n+n;i++)b[i]=(1ll*A*b[i-1]+B)%mod;
for(int i=1;i<=n+n;i++)a[i]=a[i-1]+b[i]+1;
fill(w,w+1+n+n,0);
for(int i=0,cur=0;i<=n;i++){
(w[2*i]+=cur)%=mod,(w[2*i+1]+=cur)%=mod;
cur=(cur+1ll*calc(i,i)*calc(n-i-1,n-i-1))%mod;
}
// debug(ary(w,1,n+n),ary(a,1,n+n));
int ans=0;
for(int i=1;i<=n+n;i++){
ans=(ans+a[i]%mod*(mod-w[n+n+1-i]+w[i]))%mod;
}
ans=ans*qpow(calc(n,n))%mod;
printf("%d\n",ans);
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12096kb
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: 840ms
memory: 12164kb
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: 891ms
memory: 50748kb
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:
-836655185 -103315962 1445963995 827110887 714066093 1023180349 -1357117266 1036309615 695149899 312298 1009499206 977929696 1021172873 1284117337 1091955947 -992790335 -151462449 42312781 75514602 -569297090 -524623813 -1048071254 -1987104 -44648657 558752169 1050819260 1376485762 844160548 1498771...
result:
wrong answer 1st numbers differ - expected: '1532578211', found: '-836655185'