# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259563 | tqbfjotld | Santa Claus (RMI19_santa) | C++14 | 1093 ms | 4088 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int T;
int n;
int numelf;
int lastelf;
int pos[97000];
bool iself[97000];
int val[97000];
bool test(int d,int bound){
multiset<int> presents;
for (int x = 0; x<d; x++){
if (iself[x]){
presents.insert(val[x]);
}
else{
auto it = presents.lower_bound(val[x]);
if (it!=presents.end()) {
presents.erase(it);
}
}
}
for (int x = d; x<=bound; x++){
if (iself[x]){
presents.insert(val[x]);
}
}
for (int x = d; x<=bound; x++){
if (!iself[x]){
auto it = presents.lower_bound(val[x]);
if (it!=presents.end()){
presents.erase(it);
}
}
}
//printf("test %d %d returned %d\n",d,bound,presents.empty());
return presents.empty();
}
int main(){
scanf("%d",&T);
while (T--){
scanf("%d",&n);
for (int x = 0; x<n; x++){
scanf("%d",&pos[x]);
}
lastelf = 0;
numelf=0;
for (int x = 0; x<n; x++){
int t;
scanf("%d",&t);
if (t){
iself[x] = false;
}
else {
iself[x] = true;
lastelf = max(lastelf,x);
numelf++;
}
}
for (int x = 0; x<n; x++){
scanf("%d",&val[x]);
}
for (int x = 0; x<n; x++){
if (x<lastelf) {
printf("-1 ");
continue;
}
if (x<2*numelf-1){
printf("-1 ");
continue;
}
if (!test(0,x)){
printf("-1 ");
continue;
}
int l = 0;
int r = x+1;
while (l+1<r){
int mid = (l+r)/2;
if (test(mid,x)) l = mid;
else r = mid;
}
printf("%d ",2*pos[x]-pos[l]);
}
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |