| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1336445 | yhkhoo | Bikeparking (EGOI24_bikeparking) | C++17 | 485 ms | 5128 KiB |
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n, sy, x[MAXN], y[MAXN], tx[MAXN], ty[MAXN];
inline int cmp(const int& t, const int&s){
return (t < s) - (s < t);
}
int f(int d){
memcpy(tx, x, n*sizeof(int));
memcpy(ty, y, n*sizeof(int));
int* xp = tx + n - 1, *yp = ty;
int s = 0, ret = 0;
while(s < d){
int tk, cx = xp - tx, cy = yp - ty;
if(s + min(*xp, *yp) >= d){
tk = d-s;
*xp -= tk;
*yp -= tk;
}
else{
if(*xp < *yp){
tk = *xp;
*yp -= tk;
*xp = 0;
xp--;
}
else if(*yp < *xp){
tk = *yp;
*xp -= tk;
*yp = 0;
yp++;
}
else{
tk = *xp;
*xp = 0;
*yp = 0;
xp--; yp++;
}
}
s += tk;
ret += tk * cmp(cx, cy);
}
xp = tx;
while(s < sy){
int tk, cx = xp - tx, cy = yp - ty;
if(s + min(*xp, *yp) >= sy){
tk = sy-s;
*xp -= tk;
*yp -= tk;
}
else{
if(*xp < *yp){
tk = *xp;
*yp -= tk;
*xp = 0;
xp++;
}
else if(*yp < *xp){
tk = *yp;
*xp -= tk;
*yp = 0;
yp++;
}
else{
tk = *xp;
*xp = 0;
*yp = 0;
xp++; yp++;
}
}
s += tk;
ret += tk * cmp(cx, cy);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
int sx = 0;
sy = 0;
for(int i=0; i<n; i++){
cin >> x[i];
}
for(int i=0; i<n; i++){
cin >> y[i];
sy += y[i];
}
for(int i=0; i<n; i++){
if(sy == sx){
x[i] = 0;
}
else if(sx + x[i] >= sy){
x[i] = sy - sx;
sx = sy;
}
else{
sx += x[i];
}
}
int l = 0, r = sy;
while(r - l >= 3){
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
int f1 = f(m1);
int f2 = f(m2);
if(f1 < f2){
l = m1;
}
else{
r = m2;
}
}
int ans = INT_MIN;
for(int i=l; i<=r; i++){
ans = max(ans, f(i));
}
cout << ans;
return 0;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
