QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117544#6626. Real Mountainsvalerikk#0 2ms3632kbC++171.2kb2023-07-01 16:21:032024-05-31 18:45:45

Judging History

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

  • [2024-05-31 18:45:45]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3632kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 16:21:03]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll md = 1e6 + 3;
const int N = 5005;

int n;
int h[N];

int getmn(int l, int r, int x) {
	int ret = 1e9;
	for (int i = l; i < r; ++i) {
		if (h[i] > x) {
			ret = min(ret, h[i]);
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		mx = max(mx, h[i]);
	}
	ll ans = 0;
	for (int x = 1; x < mx; ++x) {
		int l = 0;
		while (h[l] <= x) {
			++l;
		}
		int r = n - 1;
		while (h[r] <= x) {
			--r;
		}
		vector<int> kek;
		for (int i = l + 1; i < r; ++i) {
			if (h[i] == x) {
				kek.push_back(i);
			}
		}
		if (kek.empty()) {
			continue;
		}
		if (kek.size() == 1) {
			ans += x + getmn(0, kek[0], x) + getmn(kek[0] + 1, n, x);
			ans %= md;
			++h[kek[0]];
			continue;
		}
		int mnl1 = getmn(0, kek[0], x);
		int mnl2 = getmn(0, kek.back(), x);
		int mnr1 = getmn(kek[0] + 1, n, x);
		int mnr2 = getmn(kek.back() + 1, n, x);
		ans += 2 * x + min(mnl1 + mnr1 + x + 1 + mnr2, mnl2 + mnr2 + mnl1 + x + 1);
		ans += (((ll)kek.size()) - 2) * (x + x + 1 + x + 1);
		for (int i : kek) {
			++h[i];
		}
	}
	cout << ans << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 3616kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

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

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40403

result:

ok 1 number(s): "40403"

Test #4:

score: -3
Wrong Answer
time: 2ms
memory: 3632kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...

output:

49481200

result:

wrong answer 1st numbers differ - expected: '481053', found: '49481200'

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%