Submission #151375

#TimeUsernameProblemLanguageResultExecution timeMemory
151375karmaRobots (IOI13_robots)C++14
76 / 100
3091 ms26468 KiB
#include <bits/stdc++.h> #include "robots.h" #define pb emplace_back #define mp make_pair #define fi first #define se second using namespace std; const int N = int(1e6) + 1; const int M = int(5e4) + 1; int _W[N], _S[N]; struct LessW { bool operator()(const int& x, const int& y) { return _W[x] < _W[y] || (_W[x] == _W[y] && _S[x] < _S[y]); } }; struct LessS { bool operator()(const int& x, const int& y) { return _S[x] < _S[y] || (_S[x] == _S[y] && _W[x] < _W[y]); } }; priority_queue<int, vector<int>, LessW> pqw; priority_queue<int, vector<int>, LessS> pqs; vector<int> BaeW, BaeS; bitset<N> del; int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { // A -> W, B -> S for(int i = 0; i < T; ++i) { BaeW.pb(i), BaeS.pb(i); _W[i] = W[i], _S[i] = S[i]; } sort(X, X + A); sort(Y, Y + B); sort(BaeW.begin(), BaeW.end(), [](const int& i, const int& j) { return _W[i] < _W[j]; }); sort(BaeS.begin(), BaeS.end(), [](const int& i, const int& j) { return _S[i] < _S[j]; }); int low = 1, high = T, mid; while(low <= high) { mid = (low + high) >> 1; int j = 0, cur, top; del.reset(); while(pqs.size()) pqs.pop(); for(int i = 0; i < A; ++i) { while(_W[BaeW[j]] < X[i] && j < T) pqs.push(BaeW[j]), ++j; cur = mid; while(cur > 0 && !pqs.empty()) --cur, del.set(pqs.top()), pqs.pop(); } j = 0; while(pqw.size()) pqw.pop(); for(int i = 0; i < B; ++i) { while(_S[BaeS[j]] < Y[i] && j < T) { if(!del.test(BaeS[j])) pqw.push(BaeS[j]); ++j; } cur = mid; while(cur > 0 && !pqw.empty()) --cur, del.set(pqw.top()), pqw.pop(); } if(del.count() >= T) high = mid - 1; else low = mid + 1; } return low <= T? low: -1; } // //int A, B, T, X[M], Y[M], W[N], S[N]; // //int main() //{ // ios_base::sync_with_stdio(0); // cin.tie(0), cout.tie(0); // if(fopen("test.inp", "r")) { // freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); // } // cin >> A >> B >> T; // for(int i = 0; i < A; ++i) cin >> X[i]; // for(int i = 0; i < B; ++i) cin >> Y[i]; // for(int i = 0; i < T; ++i) cin >> W[i] >> S[i]; // cout << putaway(A, B, T, X, Y, W, S); //}

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:60:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(del.count() >= T) high = mid - 1;
            ~~~~~~~~~~~~^~~~
robots.cpp:45:25: warning: unused variable 'top' [-Wunused-variable]
         int j = 0, cur, top; del.reset(); while(pqs.size()) pqs.pop();
                         ^~~
#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...