QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125596#6626. Real Mountainsbashkort0 1ms3488kbC++201.8kb2023-07-16 23:38:522023-07-16 23:38:55

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-16 23:38:55]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3488kb
  • [2023-07-16 23:38:52]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int MOD = 1e6 + 3;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> h(n);

    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    ll best = 3e18;
    int p = max_element(h.begin(), h.end()) - h.begin();

    vector<bool> used(n);
    ll ans = 0;
    int f = 0;
    while (count(used.begin(), used.end(), false)) {
        int i = -1;
        if (f == 0) {
            for (int j = 0; j < n; ++j) {
                if (!used[j] && (i == -1 || h[i] > h[j])) {
                    i = j;
                }
            }
        } else {
            for (int j = n - 1; j >= 0; --j) {
                if (!used[j] && (i == -1 || h[i] > h[j])) {
                    i = j;
                }
            }
        }
        bool ok = false;
        if (i <= p) {
            if (*max_element(h.begin(), h.begin() + i + 1) == h[i]) {
                ok = true;
            }
        }
        if (i >= p) {
            if (*max_element(h.begin() + i, h.end()) == h[i]) {
                ok = true;
            }
        }
        if (ok) {
            used[i] = true;
            continue;
        }
        f ^= 1;
        int l = 1e9, r = 1e9;
        for (int j = 0; j < i; ++j) {
            if (h[j] > h[i]) {
                l = min(l, h[j]);
            }
        }
        for (int j = i + 1; j < n; ++j) {
            if (h[j] > h[i]) {
                r = min(r, h[j]);
            }
        }
        ans = ans + l + r + h[i];
        h[i] += 1;
    }

//    for (int x : h) {
//        cout << x << " ";
//    }
//    cout << '\n';

    best = min(best, ans);

    cout << best % MOD << '\n';

    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 3400kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

score: -3
Wrong Answer
time: 1ms
memory: 3392kb

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40521

result:

wrong answer 1st numbers differ - expected: '40403', found: '40521'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%