QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262250#1643. Archeologistsucup-team133#WA 1ms3608kbC++171.4kb2023-11-23 17:08:272023-11-23 17:08:28

Judging History

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

  • [2023-11-23 17:08:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2023-11-23 17:08:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<long long> v(n + 1);
    long long s = 0;
    long long c = 0;
    for (int i = 0; i < n; i++) {
        c -= a[i];
        s += (i + 1) * a[i];
        v[i + 1] = c;
    }
    auto x = v;
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    int sz = (int) v.size();
    vector<long long> pref(sz);
    vector<int> y(n + 1);
    for (int i = 0; i < n + 1; i++) {
        y[i] = (int) (lower_bound(v.begin(), v.end(), x[i]) - v.begin());
    }
    for (int i = 0; i < n; i++) {
        pref[y[i]] -= (i + 1);
        pref[y[i + 1]] += (i + 1);
    }
    for (int i = 0; i + 1 < sz; i++) {
        pref[i + 1] += pref[i];
    }
//    cerr << "x";
//    for (int i = 0; i < n; i++) {
//        cerr << " " << x[i];
//    }
//    cerr << endl;
    long long ans = 1e18;
    for (int i = 0; i < sz; i++) {
        long long t = s;
        if (v[i] - x[n] > 0) {
            t += (n + 1) * 1LL * (v[i] - x[n]);
        }
//        cerr << s << " " << t << endl;
        if (v[i] <= x[0]) {
            ans = min(ans, t);
        }
        if (i + 1 < sz) {
            s -= 2 * pref[i] * (v[i + 1] - v[i]);
        }
    }
    cout << max(0LL, ans) << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 3 -4 2 1

output:

8

result:

ok single line: '8'

Test #2:

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

input:

4
1 1 -2 3

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5
-1 -3 0 -5 -4

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3532kb

input:

100
0 -269 232 121 -422 -439 -69 478 -385 -351 38 271 -100 -153 -438 -143 41 50 200 60 92 266 340 282 -212 73 -337 70 -439 291 -191 428 303 -439 -92 -174 247 -398 2 -72 199 141 -145 -138 -226 34 120 -265 -351 20 -366 330 -381 -234 239 29 -358 -371 100 96 -179 249 380 15 201 -492 -159 -495 -366 -302 ...

output:

101606

result:

wrong answer 1st lines differ - expected: '35977', found: '101606'