250692026-02-17 19:14:23mihalykocsisVölgy (100 pont)cpp17Wrong answer 85/10041ms2344 KiB
#include <bits/stdc++.h>
using namespace std;
#define vermecske stack

int main() {
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vermecske<pair<int, int>> s;
	vector<int> ans(n, -1);
	vector<int> ans2(n, -1);
	for (int i = 0; i < n; i++) {
		while (!s.empty() && v[i] > s.top().first) {
			s.pop();
		}
		if (!s.empty()) {
			ans[i] = s.top().second;
		}
		s.push({v[i], i});
	}
	for (int i = n - 1; i >= 0; i--) {
		while (!s.empty() && v[i] > s.top().first) {
			s.pop();
		}
		if (!s.empty()) {
			ans2[i] = s.top().second;
		}
		s.push({v[i], i});
	}
	int maxi = 0;
	for (int i = 0; i < n; i++) {
		if(ans[i] != -1)maxi = max(i - ans[i], maxi);
	}
	for (int i = 0; i < n; i++) {
		if(ans2[i] != -1)maxi = max(ans2[i] - i, maxi);
	}
	cout << maxi;
}
SubtaskSumTestVerdictTimeMemory
base85/100
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms316 KiB
7Wrong answer0/51ms560 KiB
8Accepted5/51ms508 KiB
9Wrong answer0/51ms316 KiB
10Accepted5/51ms508 KiB
11Accepted5/53ms316 KiB
12Accepted5/53ms508 KiB
13Accepted5/54ms512 KiB
14Accepted5/54ms432 KiB
15Accepted5/535ms1568 KiB
16Accepted5/539ms1572 KiB
17Wrong answer0/537ms2344 KiB
18Accepted5/537ms1564 KiB
19Accepted5/537ms1580 KiB
20Accepted5/539ms1844 KiB
21Accepted5/541ms1824 KiB
22Accepted5/541ms1836 KiB