148952025-02-06 13:07:25TortelliniJrKocsirendezőcpp17Wrong answer 0/10034ms1088 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int min_moves_to_sort_cars(int N, vector<int>& P) {
    // Create a vector to store the position of each car
    vector<int> position(N + 1);
    for (int i = 0; i < N; ++i) {
        position[P[i]] = i;
    }

    // Find the length of the longest increasing subsequence (LIS)
    int lis_length = 1;
    int current_length = 1;
    for (int i = 2; i <= N; ++i) {
        if (position[i] > position[i - 1]) {
            current_length++;
            lis_length = max(lis_length, current_length);
        } else {
            current_length = 1;
        }
    }

    // Calculate the minimum number of moves
    int min_moves = N - lis_length;
    return min_moves;
}

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

    int result = min_moves_to_sort_cars(N, P);
    cout << result << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
2Wrong answer1ms316 KiB
subtask20/30
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted1ms316 KiB
6Wrong answer1ms316 KiB
7Accepted1ms316 KiB
8Wrong answer1ms508 KiB
9Accepted1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms508 KiB
17Wrong answer1ms316 KiB
18Wrong answer1ms316 KiB
19Accepted1ms624 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms356 KiB
22Wrong answer1ms316 KiB
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Accepted1ms316 KiB
subtask30/70
26Accepted1ms316 KiB
27Wrong answer1ms316 KiB
28Wrong answer2ms316 KiB
29Wrong answer3ms316 KiB
30Wrong answer4ms316 KiB
31Wrong answer8ms496 KiB
32Wrong answer8ms384 KiB
33Wrong answer17ms628 KiB
34Wrong answer29ms972 KiB
35Accepted29ms1076 KiB
36Wrong answer30ms1032 KiB
37Wrong answer30ms1048 KiB
38Wrong answer32ms1076 KiB
39Wrong answer34ms1088 KiB