146042025-01-20 14:48:05sarminRendező robot (80 pont)cpp17Accepted 80/80145ms11828 KiB
// Created by Armin on 1/20/2025.

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<int, int>;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n; cin >> n;
    vector<int> v(n);
    map<int, int> where;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      where[v[i]] = i;
    }

    int current1 = n / 2 + 1;
    int next1 = current1 + 1;
    while (next1 <= n && where[current1] < where[next1]) {
      current1 = next1;
      next1++;
    }

    int current2 = n / 2 + 1;
    int next2 = current2 - 1;
	while (next2 > 0 && where[current2] > where[next2]) {
		current2 = next2;
		next2--;
	}
    cout << max((n - current1) * 2, (current2 - 1) * 2 - 1) << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Accepted2/21ms500 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted2/22ms316 KiB
7Accepted2/22ms316 KiB
8Accepted2/21ms564 KiB
9Accepted2/22ms316 KiB
10Accepted2/22ms316 KiB
11Accepted2/22ms316 KiB
12Accepted2/22ms672 KiB
13Accepted2/22ms316 KiB
14Accepted2/22ms428 KiB
15Accepted2/22ms428 KiB
16Accepted2/22ms328 KiB
17Accepted2/22ms316 KiB
18Accepted4/4141ms11660 KiB
19Accepted4/4145ms11820 KiB
20Accepted4/4108ms11636 KiB
21Accepted4/486ms11828 KiB
22Accepted4/472ms11700 KiB
23Accepted4/468ms11828 KiB
24Accepted4/4123ms11828 KiB
25Accepted4/4136ms11828 KiB
26Accepted4/4103ms11828 KiB
27Accepted4/4105ms11828 KiB
28Accepted4/4111ms11704 KiB
29Accepted4/4108ms11828 KiB