# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
435930 | dqhungdl | 사탕 분배 (IOI21_candies) | C++17 | 157 ms | 12088 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n=c.size(),m=v.size();
vector<long long> S(m+1),Pmin(m+1),Pmax(m+1);
S[1]=v[0];
for(int i=2;i<=m;i++)
S[i]=S[i-1]+v[i-1];
Pmin.back()=Pmax.back()=S.back();
for(int i=m-1;i>=0;i--) {
Pmin[i]=min(Pmin[i+1],S[i]);
Pmax[i]=max(Pmax[i+1],S[i]);
}
vector<int> rs(n);
for(int i=0;i<n;i++) {
// If all updates are in range
if(Pmax[0]-Pmin[0]<=c[i]) {
int l=1,r=m,pivot=0;
int limit=Pmin[0];
while(l<=r) {
int mid=(l+r)/2;
if(Pmin[mid]==limit) {
l=mid+1;
pivot=mid;
}
else
r=mid-1;
}
rs[i]=S.back()-S[pivot];
continue;
}
int l=0,r=m,pivot;
while(l<=r) {
int mid=(l+r)/2;
if(Pmax[mid]-Pmin[mid]>c[i]) {
pivot=mid;
l=mid+1;
} else
r=mid-1;
}
// Find the last time touching the upper wall
if(Pmin[pivot]==S[pivot]) {
l=pivot+1,r=m;
int limit=Pmax[pivot];
while(l<=r) {
int mid=(l+r)/2;
if(Pmax[mid]==limit) {
pivot=mid;
l=mid+1;
} else
r=mid-1;
}
rs[i]=c[i]+S.back()-S[pivot];
} else { // Find the last time touching the lower wall
l=pivot+1,r=m;
int limit=Pmin[pivot];
while(l<=r) {
int mid=(l+r)/2;
if(Pmin[mid]==limit) {
pivot=mid;
l=mid+1;
} else
r=mid-1;
}
rs[i]=S.back()-S[pivot];
}
}
return rs;
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |