QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695282#9451. Expected Waiting TimeCryingWA 828ms77656kbC++141.5kb2024-10-31 19:41:582024-10-31 19:41:58

Judging History

This is the latest submission verdict.

  • [2024-10-31 19:41:58]
  • Judged
  • Verdict: WA
  • Time: 828ms
  • Memory: 77656kb
  • [2024-10-31 19:41:58]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N = 2e6+10; int mod;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
    int res = 1; a%=mod;
    while(n){
        if(n&1)res = 1ll*res*a%mod;
        n>>=1; a = 1ll*a*a%mod;
    }
    return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
int T,n,a[N],b[N],A,B,ans,sum;
int fac[N],rfac[N],pre[N];
int C(int n,int m){
    if(m<0 || n<m)return 0;
    return 1ll*fac[n]*rfac[m]%mod*rfac[n-m]%mod;
}
int C(int n){ //catlan(n)
    return subv(C(2*n,n),C(2*n,n+1));
}

void solve(){
    cin>>n>>mod>>b[0]>>A>>B;
    for(int i=1;i<=2*n;i++)b[i] = (1ll*A*b[i-1]+B)%mod,a[i] = a[i-1] + b[i] + 1;

    fac[0] = 1; for(int i=1;i<=2*n;i++)fac[i] = fac[i-1]*i%mod;
    rfac[2*n] = qinv(fac[2*n]); for(int i=2*n-1;i>=0;i--)rfac[i] = rfac[i+1]*(i+1)%mod;

    ans = sum = 0;
    for(int i=1;i<=2*n;i++)sum = (sum + a[i])%mod; sum = sum * C(n)%mod;
    pre[0] = C(n-1); for(int i=1;i<=n-1;i++)pre[i] = (pre[i-1] + C(i) * C(n-1-i))%mod;

    for(int i=2;i<=2*n;i++){  //位置i是右括号的方案数
        int res;
        if(i&1)res = pre[(i-3)/2];
        else res = pre[(i-2)/2];
        add(ans,res*2*a[i]%mod);
    }
    sub(ans,sum);
    ans = ans*qinv(C(n))%mod;
    cout<<ans<<endl;
}

signed main(){
    cin>>T;
    while(T--)solve();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9780kb

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: 802ms
memory: 9880kb

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: 828ms
memory: 77656kb

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:

1125642178
-1240073620
-1445650238
-170430028
1164646087
-1514383419
-1669057406
-208829970
-456514389
-417637522
-649604315
979771983
-273274500
540313136
-824939501
-1538187506
-995389662
-572228240
-1236045846
-521709620
-1010846805
-549033286
-93618542
-244119013
-616985938
-898798495
-155900781...

result:

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