# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259635 | cheeheng | Santa Claus (RMI19_santa) | C++14 | 1092 ms | 2680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int X[100005];
int H[100005];
int V[100005];
int D[100005];
set<ii> value;
set<ii> minValue;
bool boleh(int x, int y){
value = set<ii>();
minValue = set<ii>();
for(int i = 0; i < x; i ++){
if(H[i] == 0){
value.insert(ii(V[i], i));
}else if(H[i] == 1){
auto it = value.lower_bound(ii(V[i], -1));
if(it != value.end()){
//taken[i] = true;
//taken[(*it).second] = true;
value.erase(it);
}else{
minValue.insert(ii(V[i], i));
}
}
}
minValue = set<ii>();
for(int i = x; i <= y; i ++){
if(H[i] == 0){
value.insert(ii(V[i], i));
}else if(H[i] == 1){
minValue.insert(ii(V[i], i));
}
}
while(!value.empty() && !minValue.empty()){
int tempValue = (*value.begin()).first;
int tempMinValue = (*minValue.begin()).first;
if(tempValue >= tempMinValue){
value.erase(value.begin());
minValue.erase(minValue.begin());
}else{
break;
}
}
return value.empty();
}
int main(){
int T;
scanf("%d", &T);
while(T --){
int N;
scanf("%d", &N);
for(int i = 0; i < N; i ++){
scanf("%d", &X[i]);
}
for(int i = 0; i < N; i ++){
scanf("%d", &H[i]);
}
for(int i = 0; i < N; i ++){
scanf("%d", &V[i]);
}
int maxElfIndx = N-1;
while(H[maxElfIndx] == 1 && maxElfIndx >= 0){
maxElfIndx --;
}
if(maxElfIndx == -1){
throw;
for(int i = 0; i < N; i ++){
printf("%d ", D[i]);
}
printf("\n");
continue;
}
memset(D, -1, sizeof(D));
for(int i = 0; i < N; i ++){
if(i > maxElfIndx){
for(int j = i; j >= 0; j --){
if(boleh(j, i)){
D[i] = 2*X[i]-X[j];
break;
}
}
}
}
for(int i = 0; i < N; i ++){
printf("%d ", D[i]);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |