1892 | 2022-12-07 18:34:25 | KovácsHunor | Rendőrségi Üldözés 4 | cpp11 | Accepted 100/100 | 533ms | 4048 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1168 KiB | ||||
2 | Accepted | 2ms | 1332 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 2ms | 1656 KiB | ||||
4 | Accepted | 2ms | 1984 KiB | ||||
5 | Accepted | 2ms | 2064 KiB | ||||
6 | Accepted | 2ms | 2264 KiB | ||||
7 | Accepted | 2ms | 2244 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 2ms | 2248 KiB | ||||
9 | Accepted | 2ms | 2352 KiB | ||||
10 | Accepted | 2ms | 2424 KiB | ||||
11 | Accepted | 2ms | 2812 KiB | ||||
subtask4 | 15/15 | ||||||
12 | Accepted | 2ms | 2888 KiB | ||||
13 | Accepted | 2ms | 2876 KiB | ||||
14 | Accepted | 2ms | 2992 KiB | ||||
15 | Accepted | 2ms | 3020 KiB | ||||
subtask5 | 25/25 | ||||||
16 | Accepted | 2ms | 3000 KiB | ||||
17 | Accepted | 2ms | 2948 KiB | ||||
18 | Accepted | 2ms | 2960 KiB | ||||
19 | Accepted | 2ms | 3024 KiB | ||||
20 | Accepted | 2ms | 3012 KiB | ||||
subtask6 | 15/15 | ||||||
21 | Accepted | 2ms | 3020 KiB | ||||
22 | Accepted | 2ms | 2956 KiB | ||||
23 | Accepted | 2ms | 2940 KiB | ||||
24 | Accepted | 2ms | 3248 KiB | ||||
25 | Accepted | 3ms | 3456 KiB | ||||
subtask7 | 20/20 | ||||||
26 | Accepted | 8ms | 3536 KiB | ||||
27 | Accepted | 20ms | 3788 KiB | ||||
28 | Accepted | 57ms | 3872 KiB | ||||
29 | Accepted | 180ms | 3736 KiB | ||||
30 | Accepted | 533ms | 4048 KiB |