QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634081#9451. Expected Waiting Timeucup-team4474#WA 901ms58292kbC++202.8kb2024-10-12 16:40:382024-10-12 16:40:40

Judging History

This is the latest submission verdict.

  • [2024-10-12 16:40:40]
  • Judged
  • Verdict: WA
  • Time: 901ms
  • Memory: 58292kb
  • [2024-10-12 16:40:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

bool Memory_begin;

/*
-2 0 0 2
-5 -1 -1 1 1 5
-14 -4 -4 0 0 4 4 14
-42 -14 -14 -4 -4 4 4 14 14 42
-132 -48 -48 -20 -20 0 0 20 20 48 48 132
-429 -165 -165 -81 -81 -25 -25 25 25 81 81 165 165 429
-1430 -572 -572 -308 -308 -140 -140 0 0 140 140 308 308 572 572 1430
*/

bool Memory_end;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';

    int t;
    cin >> t;
    while (t--)
    {
        int n, p, A, B;
        cin >> n >> p;
        auto add = [&](int &x, int y) -> void
        {
            x += y;
            if (x >= p)
                x -= p;
        };
        auto minus = [&](int &x, int y) -> void
        {
            x -= y;
            if (x < 0)
                x += p;
        };

        vector<int> b(n * 2 + 1), f(n * 2 + 1), a(n * 2 + 1);
        cin >> b[0] >> A >> B;
        for (int i = 1; i <= n * 2; i++)
        {
            b[i] = 1ll * A * b[i - 1] % p;
            add(b[i], B);
            a[i] = a[i - 1];
            add(a[i], b[i]);
            add(a[i], 1);
        }

        vector<int> fac(n * 2 + 1), iv(n * 2 + 1), ifac(n * 2 + 1);
        fac[0] = ifac[0] = iv[0] = iv[1] = 1;
        for (int i = 1; i <= n * 2; i++)
            fac[i] = 1ll * fac[i - 1] * i % p;
        for (int i = 2; i <= n * 2; i++)
            iv[i] = 1ll * (p - p / i) * iv[p % i] % p;
        for (int i = 1; i <= n * 2; i++)
            ifac[i] = 1ll * ifac[i - 1] * iv[i] % p;
        auto inv = [&](int x) -> int
        {
            int y = p - 2, res = 1;
            while (y)
            {
                if (y & 1)
                    res = 1ll * res * x % p;
                x = 1ll * x * x % p;
                y >>= 1;
            }
            return res;
        };
        auto binom = [&](int x, int y) -> int
        {
            return 1ll * fac[x] * ifac[y] % p * ifac[x - y] % p;
        };
        vector<int> c(n), d(n);
        c[0] = 1;
        for (int i = 1; i < n; i++)
        {
            c[i] = binom(i * 2, i);
            minus(c[i], binom(i * 2, i + 1));
        }
        for (int i = 0; i < n; i++)
            d[i] = 1ll * c[i] * c[n - i - 1] % p;
        for (int i = 1; i < n; i++)
            add(d[i], d[i - 1]);

        for (int i = 2; i <= n * 2; i++)
        {
            int cnt = (i - 2) / 2;
            f[i] = d[cnt];
        }
        for (int i = 1; i < n * 2; i++)
        {
            int cnt = (2 * n - i - 1) / 2;
            minus(f[i], d[cnt]);
        }

        int ans = 0;
        for (int i = 1; i <= n * 2; i++)
            add(ans, 1ll * a[i] * f[i] % p);
        ans = 1ll * ans * inv(d.back()) % p;
        cout << ans << '\n';
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4048kb

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: 798ms
memory: 4316kb

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: 901ms
memory: 58292kb

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:

1100516367
68123140
1494358234
827110887
855997219
783947646
-1402766379
-364681073
-1453674410
514785458
370183133
950959997
956081548
1600457155
896728779
-941866968
896720215
-763534802
601695457
738806553
-197404394
-708260866
-1346491572
822422300
558752169
1050819260
537942922
844160548
640416...

result:

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