Submission #259635

#TimeUsernameProblemLanguageResultExecution timeMemory
259635cheehengSanta Claus (RMI19_santa)C++14
0 / 100
1092 ms2680 KiB
#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)

santa.cpp: In function 'int main()':
santa.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &T);
     ~~~~~^~~~~~~~~~
santa.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &N);
         ~~~~~^~~~~~~~~~
santa.cpp:66:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &X[i]);
             ~~~~~^~~~~~~~~~~~~
santa.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &H[i]);
             ~~~~~^~~~~~~~~~~~~
santa.cpp:72:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &V[i]);
             ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...