30942023-02-15 16:27:11peterElőzésekcpp17Accepted 100/10097ms9300 KiB
#include <stdlib.h>
#include <stdio.h>

int main() {
    int driversCount, overtakesCount;
    scanf("%d%d", &driversCount, &overtakesCount);

    int* driverNums = (int*)malloc(sizeof(int) * (driversCount + 1)); // tömb indexelése = sorrend, tömb elemei = versenyző száma
    int** driverOvertakenCount = (int**)malloc(sizeof(int*) * 2); // tömb indexelése = versenyző száma, tömb elemei = index a driverNums tömbben (sorrend)
                                                                  // második dimenzió = hányszor előzték meg
    driverOvertakenCount[0] = (int*)malloc(sizeof(int) * (driversCount + 1));
    driverOvertakenCount[1] = (int*)calloc(driversCount + 1, sizeof(int));
    for (int i = 1; i <= driversCount; i++)
    {
        scanf("%d", &driverNums[i]);
        driverOvertakenCount[0][driverNums[i]] = i;
    }

    int* overtakes = (int*)malloc(sizeof(int) * overtakesCount);
    int mostOvertaken[] = { 0, 0 }; // versenyző száma, megelőzések száma
    for (int i = 0; i < overtakesCount; i++)
    {
        scanf("%d", &overtakes[i]);

        int swap = driverNums[driverOvertakenCount[0][overtakes[i]]];
        driverNums[driverOvertakenCount[0][overtakes[i]]] = driverNums[driverOvertakenCount[0][overtakes[i]] - 1];
        driverNums[driverOvertakenCount[0][overtakes[i]] - 1] = swap;


        swap = driverOvertakenCount[0][driverNums[driverOvertakenCount[0][overtakes[i]]]];
        driverOvertakenCount[0][driverNums[driverOvertakenCount[0][overtakes[i]]]] = driverOvertakenCount[0][overtakes[i]];
        driverOvertakenCount[0][overtakes[i]] = swap;

        driverOvertakenCount[1][driverNums[driverOvertakenCount[0][overtakes[i]] + 1]]++;

        if (driverOvertakenCount[1][driverNums[driverOvertakenCount[0][overtakes[i]] + 1]] > mostOvertaken[1])
        {
            mostOvertaken[0] = driverNums[driverOvertakenCount[0][overtakes[i]] + 1];
            mostOvertaken[1] = driverOvertakenCount[1][driverNums[driverOvertakenCount[0][overtakes[i]] + 1]];
        }
        else if (driverOvertakenCount[1][driverNums[driverOvertakenCount[0][overtakes[i]] + 1]] == mostOvertaken[1]
                && driverNums[driverOvertakenCount[0][overtakes[i]] + 1] < mostOvertaken[0])
        {
            mostOvertaken[0] = driverNums[driverOvertakenCount[0][overtakes[i]] + 1];
        }
        
        printf("%d\n", mostOvertaken[0]);
    }
    

    free(driverOvertakenCount[0]);
    free(driverOvertakenCount[1]);
    free(driverOvertakenCount);
    free(overtakes);
    free(driverNums);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1236 KiB
subtask230/30
2Accepted2ms1500 KiB
3Accepted2ms1568 KiB
4Accepted3ms1764 KiB
5Accepted3ms1624 KiB
6Accepted3ms1836 KiB
7Accepted3ms1848 KiB
subtask370/70
8Accepted32ms3368 KiB
9Accepted46ms4468 KiB
10Accepted57ms5192 KiB
11Accepted46ms5488 KiB
12Accepted59ms6380 KiB
13Accepted74ms7168 KiB
14Accepted76ms8216 KiB
15Accepted94ms9300 KiB
16Accepted89ms8892 KiB
17Accepted97ms9164 KiB
18Accepted96ms9212 KiB
19Accepted64ms8308 KiB
20Accepted96ms8828 KiB
21Accepted93ms9044 KiB