QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130808#4932. Moon and Sunkaruna#WA 2ms5208kbC++171.5kb2023-07-25 10:52:422023-07-25 10:52:44

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-25 10:52:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5208kb
  • [2023-07-25 10:52:42]
  • 提交

answer

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

typedef long long ll;

const int MOD = 235813;
const int MAXN = 101010;

ll _pow(ll a, ll x) {
    ll r = 1;
    while (x) {
        if (x & 1) r = r * a % MOD;
        a = a * a % MOD;
        x /= 2;
    }
    return r;
}
int n, a[MAXN];
ll fac[MAXN], inv[MAXN];

ll binom(int n, int r) {
    return fac[n] * inv[n - r] % MOD * inv[r] % MOD;
}
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % MOD;
    inv[MAXN - 1] = _pow(fac[MAXN - 1], MOD - 2);
    for (int i = MAXN - 1; i > 0; i--) inv[i - 1] = inv[i] * i % MOD;
    ll s = 0;
    for (int i = 1; i <= n; i++) {
        ll coeff = binom(n - 1, n - i);
        if ((n - i) % 2 == 1) coeff = (MOD - coeff) % MOD;
        s = (s + (a[i] + MOD) % MOD * coeff % MOD) % MOD;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ll coeff = binom(n - 1, n - i);
        if ((n - i) % 2 == 1) coeff = (MOD - coeff) % MOD;

        ll x = (MOD - s) % MOD * _pow(coeff, MOD - 2) % MOD;
        if (x == 0) continue;
        if (a[i] + x >= -100'000 && a[i] + x <= 100'000)
            ++ans;
        else {
            x = (MOD - x) % MOD;
            if (a[i] + x >= -100'000 && a[i] + x <= 100'000)
                ++ans;
        }
    }
    cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4 1 0 7 2

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 2ms
memory: 4996kb

input:

4
10 20 30 -40

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 2ms
memory: 5208kb

input:

2
100 100

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 5036kb

input:

16
19 43 69 21 72 9 70 -15 25 29 -23 -13 -41 79 -89 93

output:

14

result:

ok single line: '14'

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 5052kb

input:

392
23531 -70064 22423 -55534 23391 -22700 88756 80526 36369 -10007 -28096 22617 -12591 80476 39531 -80144 -87955 93969 33358 30633 34132 -65817 -57922 -28367 -74214 50143 -36912 21570 -27256 -34989 14043 -92315 -12277 26859 97682 91797 -79591 30563 -58224 27016 -67737 99067 30626 16374 -49340 -1712...

output:

274

result:

wrong answer 1st lines differ - expected: '334', found: '274'