# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213294 | patrikpavic2 | Sparklers (JOI17_sparklers) | C++17 | 5 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstring>
#include <vector>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 1e5 + 500;
const ll mil = 1e9;
ll dp_L[N], dp_R[N], k, n;
ll X[N], T, tX[N];
void obrni(){
for(int i = 0;i < n;i++)
tX[i] = mil - X[i];
for(int i = 0;i < n;i++)
X[i] = tX[n - i - 1];
k = n - k - 1;
}
bool check(ll s){
ll i = 0, j = n - 1;
for(;i < k;i++){
if(i)
dp_L[i] = max(dp_L[i - 1] + (X[i] - X[i - 1]) - 2LL * s * T, 0LL);
else
dp_L[i] = 0;
}
for(;j > k;j--){
if(j == n - 1)
dp_R[j] = 0;
else
dp_R[j] = max(dp_R[j + 1] + (X[j + 1] - X[j]) - 2LL * s * T, 0LL);
}
ll ost_R = 0;
if(k + 1 < n)
ost_R = max(dp_R[k + 1] + X[k + 1] - X[k], 0LL);
//printf("ost_R = %lld\n", ost_R);
ll sum_ostalo = 0;
for(ll ii = k;ii >= 0;ii--){
//printf("dp_L[%lld] = %lld X[%lld] = %lld\n", ii, dp_L[ii], ii, X[ii]);
ll ostalo = 2LL * s * T;
if(ii)
ostalo = 2LL * s * T - (dp_L[ii - 1] + X[ii] - X[ii - 1]);
//printf("ostalo = %lld\n", ostalo);
if(sum_ostalo >= dp_L[ii - 1] + X[ii] - X[ii - 1] && sum_ostalo + 2LL * s * T >= ost_R)
return 1;
sum_ostalo += ostalo;
if(sum_ostalo < 0) break;
if(sum_ostalo >= ost_R)
return 1;
}
//printf("vracam 0\n");
return 0;
}
bool pravi(int s){
//printf("prva provjera %d\n", check(s));
bool ret = check(s);
obrni();
ret |= check(s);
//printf("druga provjera %d\n", check(s));
obrni();
return ret;
}
int main(){
scanf("%lld%lld%lld", &n, &k, &T); k--;
for(int i = 0;i < n;i++)
scanf("%lld", X + i);
ll x = 0;
for(ll i = 30;i >= 0;i--){
if(!pravi(x + (1LL << i)))
x += 1LL << i;
}
printf("%lld\n", x + 1);
}
컴파일 시 표준 에러 (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... |