Submission #65722

#TimeUsernameProblemLanguageResultExecution timeMemory
65722zubecRobots (IOI13_robots)C++14
100 / 100
2228 ms36116 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; vector <pair<int, int> > vec1; vector <int> a, b; int n, m, k; bool f(int x){ int pos = 0; priority_queue<int, vector<int>, greater<int> > q; for (int i = 0; i < n; i++){ while (pos < k && vec1[pos].first < a[i]){ q.push(-vec1[pos].second); ++pos; } for (int j = 1; j <= x; j++){ if (q.empty()) break; q.pop(); //q.erase(q.begin()); } } while(pos < vec1.size()){ q.push(-vec1[pos].second); ++pos; } for (int i = m-1; i >= 0; i--){ if (!q.empty() && -q.top() >= b[i]) return 0; for (int j = 1; j <= x; j++){ if (q.empty()) break; q.pop(); //q.erase(q.begin()); } } if (!q.empty()) return 0; return 1; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { n = A; m = B; k = T; for (int i = 0; i < n; i++){ a.push_back(X[i]); } for (int i = 0; i < m; i++){ b.push_back(Y[i]); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0; i < k; i++){ vec1.push_back({W[i], S[i]}); if (!a.empty() && W[i] < a.back()) continue; if (!b.empty() && S[i] < b.back()) continue; return -1; } sort(vec1.begin(), vec1.end()); //cout << endl; int l = 1, r = k; while(l < r){ int mid = (l+r)>>1; if (f(mid)) r = mid; else l = mid+1; } return l; } /** 3 2 10 6 2 9 4 7 4 6 8 5 2 3 7 9 1 8 5 1 3 3 8 7 7 6 10 5 */

Compilation message (stderr)

robots.cpp: In function 'bool f(int)':
robots.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(pos < vec1.size()){
           ~~~~^~~~~~~~~~~~~
#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...