QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601410#975. GamefractalWA 33ms13876kbC++171.7kb2024-09-29 23:05:482024-09-29 23:05:49

Judging History

This is the latest submission verdict.

  • [2024-09-29 23:05:49]
  • Judged
  • Verdict: WA
  • Time: 33ms
  • Memory: 13876kb
  • [2024-09-29 23:05:48]
  • Submitted

answer

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

#define F first
#define S second
#define sz(x) (int)x.size()

const int N = 1e6;

long long n;
long long a[N];

long long solve(vector<long long> A) {
    int m = A.size() - 1;
    long long ans = A[0] + A[m] + (A[0] + A[m]) / 2 * (m - 1);
    int i = 0, j = m;
    for (int k = 1; k < m; ++k) {
        if (A[i] * (j - k) + A[j] * (k - i) < A[k] * (j - i)) {
            ans += (-(A[i] * (j - k) + A[j] * (k - i)) + A[k] * (j - i)) / 2;
            i = k;
        }
    }
    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] *= 2;
    }
    long long mx = *max_element(a + 1, a + n + 1);
    int L = n + 1, R = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == mx) {
            L = min(L, i);
            R = max(R, i);
        }
    }
    long long ans = 0;
    vector<long long> v;
    if (L == n || R == 1) {
        v = vector<long long>(a + 1, a + n + 1);
        if (R == 1) reverse(v.begin(), v.end());
        ans += solve(v);
    }
    else {
        ans += mx * max(0, (R - L - 1)) / 2;
        if (L > 1) {
            v = vector<long long>(a + 1, a + L + 1);
            ans += solve(v);
        }
        if (R < n) {
            v = vector<long long>(a + R, a + n + 1);
            reverse(v.begin(), v.end());
            ans += solve(v);
        }
        if (L == R) ans -= mx;
    }
    long long r = 1;
    n *= 2;
    const int mod = 998244353;
    long long pw = mod - 2;
    while (pw) {
        if (pw & 1) r = (r * n) % mod;
        n = (n * n) % mod;
        pw /= 2;
    }
ans %= mod;
    ans = (ans * r) % mod;
    cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

3
3 1 2

output:

499122179

result:

ok "499122179"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

6
6 1 2 5 3 4

output:

582309211

result:

ok "582309211"

Test #3:

score: -100
Wrong Answer
time: 33ms
memory: 13876kb

input:

500000
131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...

output:

231747618

result:

wrong answer 1st words differ - expected: '131032905', found: '231747618'