149482025-02-09 12:49:37PKBRendező robot (80 pont)cpp17Wrong answer 11/80129ms10664 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;  // Store the position of each number
    }

    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 sequence when order breaks
        }
        max_sorted_len = max(max_sorted_len, current_length);
    }

    cout << N - max_sorted_len+1 << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base11/80
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/21ms500 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms548 KiB
6Wrong answer0/22ms316 KiB
7Wrong answer0/22ms316 KiB
8Wrong answer0/22ms316 KiB
9Wrong answer0/22ms316 KiB
10Wrong answer0/22ms316 KiB
11Wrong answer0/22ms500 KiB
12Wrong answer0/22ms316 KiB
13Wrong answer0/22ms316 KiB
14Accepted2/22ms316 KiB
15Wrong answer0/22ms544 KiB
16Wrong answer0/22ms316 KiB
17Accepted2/22ms508 KiB
18Wrong answer0/4115ms10524 KiB
19Wrong answer0/4129ms10528 KiB
20Wrong answer0/4108ms10664 KiB
21Wrong answer0/4103ms10664 KiB
22Wrong answer0/4104ms10664 KiB
23Wrong answer0/4101ms10664 KiB
24Wrong answer0/4109ms10664 KiB
25Wrong answer0/4128ms10520 KiB
26Wrong answer0/4104ms10528 KiB
27Wrong answer0/4111ms10528 KiB
28Accepted4/4104ms10476 KiB
29Wrong answer0/4104ms10664 KiB