QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#635083#9451. Expected Waiting Timeucup-team4906#WA 969ms46452kbC++201.8kb2024-10-12 18:59:092024-10-12 18:59:10

Judging History

This is the latest submission verdict.

  • [2024-10-12 18:59:10]
  • Judged
  • Verdict: WA
  • Time: 969ms
  • Memory: 46452kb
  • [2024-10-12 18:59:09]
  • Submitted

answer

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

#define N 2000010
int fac[N], inv[N];
int a[N], b[N];
int f[N], g[N];
int n, P, A, B;
int C(int n, int m) {return 1LL * fac[n] * inv[m] % P * inv[n - m] % P;}
int qpow(int a, int b)
{
    int ans = 1;
    while (b) {if (b & 1) ans = 1LL * ans * a % P; b >>= 1; a = 1LL * a * a % P;}
    return ans;
}
void sol()
{  
    cin >> n >> P >> b[0] >> A >> B;
    for (int i = 1; i <= 2 * n; i ++)
    {
        b[i] = (1LL * A * b[i - 1] + B) % P;
        a[i] = (a[i - 1] + b[i] + 1) % P;
    }
    fac[0] = 1;
    for (int i = 1; i <= 2 * n; i ++) fac[i] = 1LL * fac[i - 1] * i % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= 2 * n; i ++) inv[i] = 1LL * (P - P / i) * inv[P % i] % P;
    for (int i = 2; i <= 2 * n; i ++) inv[i] = 1LL * inv[i] * inv[i - 1] % P;

    f[0] = 1;
    for (int i = 1; i <= n; i ++)f[i] = (C(2 * i, i) + P - C(2 * i, i - 1)) % P;
    for (int i = 0; i <= n - 1; i ++)g[i] = 1LL * f[i] * f[(2 * n - 2 - i * 2) / 2] % P;
    for (int i = 0; i <= n - 1; i ++)g[i] = (g[i] + (i ? g[i - 1] : 0)) % P;
    int ans = 0;
    // cout << "??:" << g[0] << endl;
    // for (int i = 1; i <= 2 * n; i ++) cout << a[i] << ' '; cout << endl;
    for (int i = 1; i <= 2 * n; i ++)
    {
        int t = (2 * n - i - 1) / 2;
        // cout << "EEE:" << i << ' ' << (2 * n - i - 1) / 2 << ' ' << (i - 2) / 2 << '\n';
        if (i < 2 * n)ans = (ans + 1LL * (P - a[i]) * g[t]) % P;

        t = (i - 2) / 2;
        if (i > 1)ans = (ans + 1LL * a[i] * g[t]) % P;
    }  

    ans = 1LL * ans * qpow(f[n], P - 2) % P;
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T --) sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 944ms
memory: 11848kb

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: 969ms
memory: 46452kb

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:

-134720567
-1111658827
-1031393775
827110887
695899770
-121846738
974461005
-631972015
1293431776
134216351
129116879
793070751
-1054442673
-1423648804
-276835620
1796124457
-945823859
548709853
-809303888
221202583
953274186
-1365376588
-874561356
539622309
558752169
1050819260
-341951483
844160548...

result:

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