#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 1005, INF = 1e9;
int n, k, t, a[MXN];
int c[MXN];
int pre[MXN], suf[MXN];
int DC(int a, int b) {
if (a == 0) return 0;
return (a - 1) / b + 1;
}
int PUSH(int l, int r) {
// from l to r, l-th person just lighted its firecracker on;
int ans = 0;
FOR(i, l + 1, r) {
ans = max(ans, DC(a[i] - a[i - 1], 2 * t));
}
return ans;
}
void init() {
FOR(i, 1, n) pre[i] = max(pre[i - 1], DC(a[i] - a[i - 1], 2 * t));
for (int i = n - 2; i >= 0; i--) suf[i] = max(suf[i + 1], DC(a[i + 1] - a[i], 2 * t));
}
bool check(int l, int r, int x) {
debug(l, r, x);
if (l == -1) {
return (suf[r - 1] <= x);
}
if (r == n) {
return (pre[l + 1] <= x);
}
int lap = a[l + 1] - a[l], rap = a[r] - a[r - 1];
if (2 * x * t < min(lap, rap)) return false;
if (2 * x * t >= lap + rap) {
if (max(pre[l], suf[r]) <= x) return true;
}
if (l > 0 && 2 * x * t >= lap + (a[l] - a[l - 1])) {
if (max(pre[l - 1], suf[r - 1]) <= x) return true;
}
if (r < n - 1 && 2 * x * t >= rap + (a[r + 1] - a[r])) {
if (max(pre[l + 1], suf[r + 1]) <= x) return true;
}
if (2 * x * t >= max(lap, rap)) {
if (lap >= rap) {
return check(l - 1, r, x);
} else {
return check(l, r + 1, x);
}
}
if (lap >= rap) return check(l, r + 1, x);
else return check(l - 1, r, x);
return false;
}
int miku() {
cin >> n >> k >> t;
k--;
FOR(i, 0, n) cin >> a[i];
if (k == n - 1) {
FOR(i, 0, n) a[i] = a[n - 1] - a[i];
reverse(a, a + n);
k = 0;
}
if (k == 0) return PUSH(0, n);
init();
int l = 0, r = INF;
// while (l + 1 < r) {
// debug(l, r);
// int mid = (l + r) >> 1;
// (check(k - 1, k + 1, mid) ? r : l) = mid;
// }
// debug(check(0, 2, 8));
check(0, 2, 8);
// return 0;
return r;
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
cout << miku() << '\n';
return 0;
}
Compilation message
sparklers.cpp: In function 'bool check(long long int, long long int, long long int)':
sparklers.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
sparklers.cpp:46:5: note: in expansion of macro 'debug'
46 | debug(l, r, x);
| ^~~~~
sparklers.cpp: In function 'long long int miku()':
sparklers.cpp:87:9: warning: unused variable 'l' [-Wunused-variable]
87 | int l = 0, r = INF;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |