30942023-02-15 16:27:11peterElőzésekcpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva3ms1236 KiB
subtask230/30
2Elfogadva2ms1500 KiB
3Elfogadva2ms1568 KiB
4Elfogadva3ms1764 KiB
5Elfogadva3ms1624 KiB
6Elfogadva3ms1836 KiB
7Elfogadva3ms1848 KiB
subtask370/70
8Elfogadva32ms3368 KiB
9Elfogadva46ms4468 KiB
10Elfogadva57ms5192 KiB
11Elfogadva46ms5488 KiB
12Elfogadva59ms6380 KiB
13Elfogadva74ms7168 KiB
14Elfogadva76ms8216 KiB
15Elfogadva94ms9300 KiB
16Elfogadva89ms8892 KiB
17Elfogadva97ms9164 KiB
18Elfogadva96ms9212 KiB
19Elfogadva64ms8308 KiB
20Elfogadva96ms8828 KiB
21Elfogadva93ms9044 KiB