Submission #404693

#TimeUsernameProblemLanguageResultExecution timeMemory
404693peuchRobots (IOI13_robots)C++17
100 / 100
1949 ms25560 KiB
#include "robots.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int n, m, t; int x[MAXN], y[MAXN]; pair<int, int> v[MAXN]; int bb(); bool test(int val); int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { n = A, m = B, t = T; for(int i = 0; i < t; i++) v[i] = make_pair(W[i], S[i]); for(int i = 0; i < n; i++) x[i] = X[i]; for(int i = 0; i < m; i++) y[i] = Y[i]; sort(v, v + t); sort(x, x + n); sort(y, y + m); reverse(v, v + t); reverse(x, x + n); reverse(y, y + m); return bb(); } int bb(){ int ini = 1, fim = t; if(!test(t + 1)) return -1; while(ini != fim){ int mid = (ini + fim) >> 1; if(test(mid)) fim = mid; else ini = mid + 1; } return ini; } bool test(int val){ if(m == 0){ int naoPego = 0; for(int i = 0; i < n; i++){ if(v[naoPego].first >= x[i]) return 0; naoPego += val; if(naoPego >= t) return 1; } return 0; } int it1 = 0; priority_queue<int> sobra; priority_queue<int> pegando; int podePega = val; while(it1 != t && v[it1].first >= x[0]) sobra.push(v[it1++].second); for(int i = 0; i < n; i++){ while(it1 != t && v[it1].first >= x[i + 1]) pegando.push(v[it1++].second); while(!pegando.empty() && podePega){ pegando.pop(); podePega--; } podePega += val; while(!pegando.empty()){ sobra.push(pegando.top()); pegando.pop(); } } podePega = val; for(int i = 0; i < m; i++){ if(sobra.empty()) break; if(sobra.top() >= y[i]) return 0; while(!sobra.empty() && podePega){ sobra.pop(); podePega--; } podePega = val; } return sobra.empty(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...