Submission #703266

#TimeUsernameProblemLanguageResultExecution timeMemory
703266speedyArdaRobots (IOI13_robots)C++14
100 / 100
1482 ms24324 KiB
#include "robots.h" #include "bits/stdc++.h" using namespace std; // Sol O(nlog(n)^2) int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { sort(X, X + A); sort(Y, Y + B); int ans = 1e9; vector< pair<int, int> > sorted; for(int i = 0; i < T; i++) { sorted.push_back({W[i], S[i]}); } sort(sorted.begin(), sorted.end()); //reverse(sorted.begin(), sorted.end()); int l = 1, r = T; //cout << "hm\n"; while(l <= r) { int m = (l + r) / 2; //cout << m << "\n"; //unordered_set<int, greater<int> > curr; priority_queue<int> curr; int idx = 0; for(int i = 0; i < A; i++) { while(idx < T && sorted[idx].first < X[i]) { curr.push(sorted[idx].second); idx++; } int cnt = 0; while(cnt < m && !curr.empty()) { curr.pop(); cnt++; } } while(idx < T) // Elements whose weights are higher than our strongest weak robot. { curr.push(sorted[idx].second); idx++; } for(int i = B - 1; i >= 0; i--) { int cnt = 0; while(cnt < m && !curr.empty() && Y[i] > (curr.top())) { curr.pop(); cnt++; } } if(curr.size() == 0) { ans = m; r = m - 1; } else l = m + 1; } if(ans == 1e9) ans = -1; return ans; //return 42; }
#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...