8807 | 2024-01-31 10:04:19 | Error42 | Rendőrségi Üldözés 4 | cpp17 | Accepted 100/100 | 463ms | 4684 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
ll first_green(ll const cur_t, ll const t) {
ll cycle = cur_t % (2 * t);
if (cycle < t)
return cur_t;
else
return cur_t / (2 * t) * (2 * t) + 2 * t;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, r, t, l;
cin >> n >> r >> t >> l;
vector<ll> x(n);
for (ll& y : x)
cin >> y;
vector<ll> dp(r + 1);
for (int i = 0; i <= r; i++)
dp[i] = x[0];
for (int i = 0; i < n; i++) {
// get through lamp
for (int j = r; j >= 1; j--) {
dp[j] = min(first_green(dp[j], t), dp[j - 1]);
}
dp[0] = first_green(dp[0], t);
// to next lamp
if (i != n - 1) {
for (int j = 0; j <= r; j++)
dp[j] += x[i + 1] - x[i];
}
}
cout << dp[r] + l - x.back() << "\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1700 KiB | ||||
2 | Accepted | 3ms | 1864 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2096 KiB | ||||
4 | Accepted | 3ms | 2268 KiB | ||||
5 | Accepted | 2ms | 2348 KiB | ||||
6 | Accepted | 2ms | 2356 KiB | ||||
7 | Accepted | 3ms | 2572 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 3ms | 2788 KiB | ||||
9 | Accepted | 3ms | 2900 KiB | ||||
10 | Accepted | 2ms | 2992 KiB | ||||
11 | Accepted | 3ms | 3104 KiB | ||||
subtask4 | 15/15 | ||||||
12 | Accepted | 3ms | 3112 KiB | ||||
13 | Accepted | 3ms | 3312 KiB | ||||
14 | Accepted | 3ms | 3448 KiB | ||||
15 | Accepted | 3ms | 3656 KiB | ||||
subtask5 | 25/25 | ||||||
16 | Accepted | 2ms | 3580 KiB | ||||
17 | Accepted | 2ms | 3584 KiB | ||||
18 | Accepted | 3ms | 3576 KiB | ||||
19 | Accepted | 3ms | 3584 KiB | ||||
20 | Accepted | 3ms | 3888 KiB | ||||
subtask6 | 15/15 | ||||||
21 | Accepted | 3ms | 3756 KiB | ||||
22 | Accepted | 3ms | 3648 KiB | ||||
23 | Accepted | 3ms | 3640 KiB | ||||
24 | Accepted | 3ms | 3908 KiB | ||||
25 | Accepted | 3ms | 3916 KiB | ||||
subtask7 | 20/20 | ||||||
26 | Accepted | 8ms | 4072 KiB | ||||
27 | Accepted | 18ms | 4092 KiB | ||||
28 | Accepted | 50ms | 4356 KiB | ||||
29 | Accepted | 156ms | 4640 KiB | ||||
30 | Accepted | 463ms | 4684 KiB |