30952023-02-15 16:27:59peterElőzésekcpp17Time limit exceeded 30/1003.075s5156 KiB
/**
 * időlimit túllépés 
 **/

#include <stdlib.h>
#include <stdio.h>

typedef struct Driver {
    int driverNum;
    int overtakenCount;
} Driver;

int driversCount;
int overtake(Driver* drivers, int overtaker) {
    int overtakerIndex = 1;
    while (overtakerIndex < driversCount && drivers[overtakerIndex].driverNum != overtaker)
    {
        overtakerIndex++;
    }
    Driver swap = drivers[overtakerIndex];
    drivers[overtakerIndex] = drivers[overtakerIndex - 1];
    drivers[overtakerIndex - 1] = swap;
    drivers[overtakerIndex].overtakenCount++;
    return overtakerIndex;
}

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

    Driver* drivers = (Driver*)malloc(sizeof(Driver)*driversCount);
    for (int i = 0; i < driversCount; i++)
    {
        scanf("%d", &drivers[i].driverNum);
        drivers[i].overtakenCount = 0;
    }

    int* overtakes = (int*)malloc(sizeof(int)*overtakesCount);
    Driver mostOvertaken = drivers[1];
    for (int i = 0; i < overtakesCount; i++)
    {
        scanf("%d", &overtakes[i]);
        int overtaken = overtake(drivers, overtakes[i]);
        
        if (drivers[overtaken].overtakenCount > mostOvertaken.overtakenCount)
        {
            mostOvertaken = drivers[overtaken];
        }
        else if (drivers[overtaken].overtakenCount == mostOvertaken.overtakenCount && drivers[overtaken].driverNum < mostOvertaken.driverNum)
        {
            mostOvertaken = drivers[overtaken];
        }
        printf("%d\n", mostOvertaken.driverNum);
    }

    free(drivers);
    free(overtakes);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1432 KiB
subtask230/30
2Accepted3ms1696 KiB
3Accepted2ms1536 KiB
4Accepted3ms1832 KiB
5Accepted3ms2036 KiB
6Accepted4ms2216 KiB
7Accepted4ms2264 KiB
subtask30/70
8Accepted1.521s3492 KiB
9Time limit exceeded3.072s3172 KiB
10Time limit exceeded3.039s3508 KiB
11Time limit exceeded3.055s3904 KiB
12Time limit exceeded3.059s3868 KiB
13Time limit exceeded3.065s4436 KiB
14Time limit exceeded3.063s4564 KiB
15Time limit exceeded3.043s4712 KiB
16Time limit exceeded3.072s4716 KiB
17Time limit exceeded3.052s4732 KiB
18Time limit exceeded3.055s5020 KiB
19Time limit exceeded3.059s5008 KiB
20Time limit exceeded3.055s5140 KiB
21Time limit exceeded3.075s5156 KiB