30912023-02-15 16:03:27peterElőzésekcpp17Wrong answer 0/10097ms9736 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]]]]++;

        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 answer3ms1360 KiB
subtask20/30
2Wrong answer3ms1624 KiB
3Wrong answer3ms1880 KiB
4Wrong answer3ms2032 KiB
5Wrong answer3ms2032 KiB
6Wrong answer3ms2164 KiB
7Wrong answer3ms2300 KiB
subtask30/70
8Wrong answer32ms3504 KiB
9Wrong answer48ms4896 KiB
10Wrong answer57ms5612 KiB
11Wrong answer46ms5932 KiB
12Wrong answer57ms7048 KiB
13Wrong answer72ms7752 KiB
14Wrong answer78ms8600 KiB
15Wrong answer94ms9736 KiB
16Wrong answer87ms9332 KiB
17Wrong answer97ms9616 KiB
18Wrong answer96ms9612 KiB
19Wrong answer63ms8748 KiB
20Wrong answer92ms9488 KiB
21Wrong answer87ms9428 KiB