149492025-02-09 12:50:27PKBRendező robot (80 pont)cpp17Wrong answer 14/80127ms10668 KiB
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> arr(N);
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }

    unordered_map<int, int> pos;
    for (int i = 0; i < N; ++i) {
        pos[arr[i]] = i;
    }

    int max_sorted_len = 1, current_length = 1;

    for (int i = 2; i <= N; ++i) {
        if (pos[i] > pos[i - 1]) {
            current_length++;
        } else {
            current_length = 1; // reset
        }
        max_sorted_len = max(max_sorted_len, current_length);
    }

    cout << N - max_sorted_len << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base14/80
1Wrong answer0/01ms316 KiB
2Accepted0/01ms316 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/22ms316 KiB
7Wrong answer0/22ms316 KiB
8Wrong answer0/22ms316 KiB
9Accepted2/22ms316 KiB
10Wrong answer0/22ms408 KiB
11Wrong answer0/22ms316 KiB
12Accepted2/22ms316 KiB
13Accepted2/22ms316 KiB
14Wrong answer0/22ms316 KiB
15Wrong answer0/22ms316 KiB
16Wrong answer0/22ms316 KiB
17Wrong answer0/22ms500 KiB
18Accepted4/4127ms10520 KiB
19Accepted4/4115ms10524 KiB
20Wrong answer0/4112ms10528 KiB
21Wrong answer0/4100ms10524 KiB
22Wrong answer0/4101ms10664 KiB
23Wrong answer0/4103ms10564 KiB
24Wrong answer0/4116ms10668 KiB
25Wrong answer0/4120ms10524 KiB
26Wrong answer0/4104ms10664 KiB
27Wrong answer0/4120ms10660 KiB
28Wrong answer0/4103ms10528 KiB
29Wrong answer0/4101ms10664 KiB