# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
550652 | LucaDantas | Sparklers (JOI17_sparklers) | C++17 | 1 ms | 212 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 25, inf = 0x3f3f3f3f;
int x[maxn], n, k, T;
vector<vector<int>> possibilidades;
vector<int> aux;
void brute(int l, int r) {
if(aux.size() == n) {
static vector<int> tempo;
tempo.clear(); tempo.resize(n);
for(int i = 0; i < n; i++)
tempo[aux[i]] = i+1; // 1-indexed, no need to add 1 when considering it later
tempo[aux[n-1]] = n-1;
possibilidades.push_back(tempo);
return;
}
if(l >= 0) {
aux.push_back(l);
brute(l-1, r);
aux.pop_back();
}
if(r < n) {
aux.push_back(r);
brute(l, r+1);
aux.pop_back();
}
}
bool check(int s) {
for(const vector<int>& ordem : possibilidades) {
int posL = inf;
bool bad = 0;
for(int i = 0; i < k; i++) {
if(x[i] - posL > 1ll * ordem[i] * T * s)
{ bad = 1; break; } // não dá pra eu chegar no anterior
posL = (int)min(1ll * posL, x[i] + 1ll * ordem[i] * T * s);
}
int posR = 0;
for(int i = k; i < n; i++) {
if(posR - x[i] > 1ll * ordem[i] * T * s)
{ bad = 1; break; }
posR = (int)max(1ll * posR, x[i] - 1ll * ordem[i] * T * s);
}
if(bad) continue;
if(posL >= posR)
return 1;
}
return 0;
}
int main() {
scanf("%d %d %d", &n, &k, &T); --k; // 0-indexed
for(int i = 0; i < n; i++)
scanf("%d", x+i);
aux.push_back(k);
brute(k-1, k+1);
int l = 0, r = inf, ans = -1;
while(l <= r) {
int m = (l+r) >> 1;
if(check(m))
r = m-1, ans = m;
else
l = m+1;
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |