1902 | 2022-12-08 13:30:11 | peter | Rendőrségi Üldözés 4 | cpp17 | Accepted 100/100 | 606ms | 238644 KiB |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int varakozas(int ido, int periodus)
{
int ret = 2 * periodus - (ido % (2 * periodus)) <= periodus ? 2 * periodus - (ido % (2 * periodus)) : 0;
return ret;
}
int main()
{
int n, r, t, l;
scanf("%d %d %d %d", &n, &r, &t, &l);
int* x = (int*)malloc(sizeof(int) * (n + 1));
x[0] = 0;
for (int i = 1; i < n + 1; i++)
{
scanf("%d", &x[i]);
}
int** sols = (int**)malloc(sizeof(int*) * (r + 1));
for (int i = 0; i < r + 1; i++)
{
sols[i] = (int*)malloc(sizeof(int) * (n + 1));
sols[i][0] = 0;
}
for (int i = 1; i < n + 1; i++)
{
sols[0][i] = sols[0][i - 1] + x[i] - x[i - 1] + varakozas(sols[0][i - 1] + x[i] - x[i - 1], t);
}
for (int i = 1; i < r + 1; i++)
{
for (int j = 1; j < n + 1; j++)
{
int var = sols[i][j - 1] + x[j] - x[j - 1] + varakozas(sols[i][j - 1] + x[j] - x[j - 1], t);
int atmegy = sols[i - 1][j - 1] + x[j] - x[j - 1];
sols[i][j] = var < atmegy ? var : atmegy;
}
}
printf("%d", sols[r][n] + l - x[n]);
free(x);
for (int i = 0; i < r + 1; i++)
{
free(sols[i]);
}
free(sols);
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1236 KiB | ||||
2 | Accepted | 2ms | 1560 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 2ms | 1604 KiB | ||||
4 | Accepted | 2ms | 1808 KiB | ||||
5 | Accepted | 2ms | 2056 KiB | ||||
6 | Accepted | 2ms | 2308 KiB | ||||
7 | Accepted | 2ms | 2472 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 2ms | 2332 KiB | ||||
9 | Accepted | 2ms | 2400 KiB | ||||
10 | Accepted | 2ms | 2372 KiB | ||||
11 | Accepted | 2ms | 2556 KiB | ||||
subtask4 | 15/15 | ||||||
12 | Accepted | 2ms | 2852 KiB | ||||
13 | Accepted | 2ms | 2792 KiB | ||||
14 | Accepted | 2ms | 2612 KiB | ||||
15 | Accepted | 2ms | 2768 KiB | ||||
subtask5 | 25/25 | ||||||
16 | Accepted | 2ms | 2884 KiB | ||||
17 | Accepted | 2ms | 2816 KiB | ||||
18 | Accepted | 2ms | 3172 KiB | ||||
19 | Accepted | 2ms | 3120 KiB | ||||
20 | Accepted | 2ms | 3308 KiB | ||||
subtask6 | 15/15 | ||||||
21 | Accepted | 2ms | 2916 KiB | ||||
22 | Accepted | 2ms | 3312 KiB | ||||
23 | Accepted | 2ms | 3408 KiB | ||||
24 | Accepted | 2ms | 3500 KiB | ||||
25 | Accepted | 3ms | 3788 KiB | ||||
subtask7 | 20/20 | ||||||
26 | Accepted | 9ms | 6076 KiB | ||||
27 | Accepted | 24ms | 11564 KiB | ||||
28 | Accepted | 64ms | 27296 KiB | ||||
29 | Accepted | 210ms | 82132 KiB | ||||
30 | Accepted | 606ms | 238644 KiB |