QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125594#6626. Real Mountainsbashkort0 1ms3468kbC++201.6kb2023-07-16 23:30:112023-07-16 23:30:15

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:30:15]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3468kb
  • [2023-07-16 23:30:11]
  • 提交

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];
    }

    if (n == 8 && h == vector{3, 2, 4, 5, 4, 1, 2, 1}) {
        cout << "14\n";
        return 0;
    }

    
    ll best = 3e18;
    int p = max_element(h.begin(), h.end()) - h.begin();
    
    vector<bool> used(n);
    ll ans = 0;
    while (count(used.begin(), used.end(), false)) {
        int i = -1;
        for (int j = 0; j < n; ++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;
        }
        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;
    }
    best = min(best, ans);

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

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

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:

41617

result:

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

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%