30922023-02-15 16:05:58peterElőzésekcpp17Wrong answer 0/10096ms9868 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]);
    }
    for (int i = 0; i < overtakesCount; 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]]]]++;

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





    free(driverOvertakenCount[0]);
    free(driverOvertakenCount[1]);
    free(driverOvertakenCount);
    free(overtakes);
    free(driverNums);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1288 KiB
subtask20/30
2Wrong answer3ms1620 KiB
3Wrong answer2ms1712 KiB
4Wrong answer3ms2028 KiB
5Wrong answer3ms2180 KiB
6Wrong answer3ms2500 KiB
7Wrong answer3ms2460 KiB
subtask30/70
8Wrong answer32ms4044 KiB
9Wrong answer46ms5520 KiB
10Wrong answer57ms5944 KiB
11Wrong answer46ms6400 KiB
12Wrong answer57ms7192 KiB
13Wrong answer72ms7696 KiB
14Wrong answer76ms8468 KiB
15Wrong answer96ms9488 KiB
16Wrong answer89ms9320 KiB
17Wrong answer96ms9644 KiB
18Wrong answer96ms9868 KiB
19Wrong answer64ms8988 KiB
20Wrong answer92ms9444 KiB
21Wrong answer90ms9644 KiB