18922022-12-07 18:34:25KovácsHunorRendőrségi Üldözés 4cpp11Accepted 100/100533ms4048 KiB
#include "stdio.h"
#include "stdlib.h"

int n, r, t, l;
int* arr1;
int* arr2;

int wait(int time){
    return time%(t*2)<t ? 0 : t*2 - time%(t*2);
}

int min(int a, int b){
    return a<b ? a : b;
}

void swap(){
    int* temp;
    temp = arr1;
    arr1 = arr2;
    arr2 = temp;
}
int main()
{
    scanf("%d%d%d%d", &n, &r, &t, &l);
    int* lamps = (int*)malloc(sizeof(int)*(n+1));
    arr1 = (int*)malloc(sizeof(int)*(n+1));
    arr2 = (int*)malloc(sizeof(int)*(n+1));
    arr1[0] = 0;
    arr2[0] = 0;
    lamps[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", lamps + i);
        arr1[i] = arr1[i-1] + lamps[i] - lamps[i-1];
        arr1[i] += wait(arr1[i]);
    }
    for (int i = 1; i <= r; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            int distance = lamps[j] - lamps[j-1];
            arr2[j] = min(arr1[j-1] + distance, arr2[j-1] + distance + wait(arr2[j-1] + distance));
        }
        swap();
    }
    printf("%d", arr1[n] + l - lamps[n]);
    free(lamps);
    free(arr1);
    free(arr2);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1168 KiB
2Accepted2ms1332 KiB
subtask210/10
3Accepted2ms1656 KiB
4Accepted2ms1984 KiB
5Accepted2ms2064 KiB
6Accepted2ms2264 KiB
7Accepted2ms2244 KiB
subtask315/15
8Accepted2ms2248 KiB
9Accepted2ms2352 KiB
10Accepted2ms2424 KiB
11Accepted2ms2812 KiB
subtask415/15
12Accepted2ms2888 KiB
13Accepted2ms2876 KiB
14Accepted2ms2992 KiB
15Accepted2ms3020 KiB
subtask525/25
16Accepted2ms3000 KiB
17Accepted2ms2948 KiB
18Accepted2ms2960 KiB
19Accepted2ms3024 KiB
20Accepted2ms3012 KiB
subtask615/15
21Accepted2ms3020 KiB
22Accepted2ms2956 KiB
23Accepted2ms2940 KiB
24Accepted2ms3248 KiB
25Accepted3ms3456 KiB
subtask720/20
26Accepted8ms3536 KiB
27Accepted20ms3788 KiB
28Accepted57ms3872 KiB
29Accepted180ms3736 KiB
30Accepted533ms4048 KiB