QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634698 | #9451. Expected Waiting Time | ucup-team4938# | WA | 794ms | 48716kb | C++14 | 1.3kb | 2024-10-12 17:55:14 | 2024-10-12 17:55:14 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
int mod, n, A, B, a[2000010], b[2000010], c[2000010], f[2000010], fac[2000010], ifac[2000010];
void add(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int qmd(int x){return x<mod?x:x-mod;}
int qpw(int x,int y=mod-2){int res=1;while(y>0){if(y&1)res=(ll)res*x%mod;x=(ll)x*x%mod;y>>=1;}return res;}
int H(int x){return (ll)fac[x<<1]*ifac[x]%mod*ifac[x+1]%mod;}
void solve(){
int i, ans = 0;
scanf("%d%d%d%d%d", &n, &mod, &b[0], &A, &B);
for(i = 1, fac[0] = 1; i <= n << 1; i++){
fac[i] = (ll)fac[i - 1] * i % mod;
}
for(i = n << 1, ifac[n << 1] = qpw(fac[n << 1]); i > 0; i--){
ifac[i - 1] = (ll)ifac[i] * i % mod;
}
for(i = 0; i <= n; i++){
f[i] = (ll)H(i) * H(n - i - 1) % mod;
if(i > 0) add(f[i], f[i - 1]);
// printf("%d %d %d %d %d\n", i, fac[i], ifac[i], H(i), f[i]);
}
for(i = 1, a[0] = 0, c[0] = 0; i <= n << 1; i++){
b[i] = ((ll)A * b[i - 1] + B) % mod;
a[i] = qmd(a[i - 1] + b[i] + 1);
c[i] = a[i];
// printf("%d %d %d %d\n", i, a[i], b[i], c[i]);
}
for(i = 1; i <= n << 1; i++){
if(i >= 2) ans = (ans + (ll)c[i] * f[(i >> 1) - 1]) % mod;
if(i <= (n << 1) - 1) ans = (ans + (ll)c[i] * (mod - f[(n << 1) - i - 1 >> 1])) % mod;
}
printf("%lld\n", (ll)ans * qpw(H(n)) % mod);
}
int main()
{
int t;
scanf("%d", &t);
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 14136kb
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: 762ms
memory: 14184kb
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: 794ms
memory: 48716kb
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:
1389521166 1148921540 1309981581 827110887 668144542 874308887 -1021444867 -1702791753 -1289229611 1309538570 228161305 793070751 1197243715 -31342180 878699953 1068222207 1107475679 -267160808 155057172 434743296 315534406 -136143036 -811665022 92236767 558752169 1050819260 -1451889901 844160548 98...
result:
wrong answer 1st numbers differ - expected: '1532578211', found: '1389521166'