Submission #101371

#TimeUsernameProblemLanguageResultExecution timeMemory
101371MohamedAhmed0Robots (IOI13_robots)C++14
100 / 100
1119 ms24808 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std ; const int MAX = 50005 ; int n , m ; int Weight[MAX] , Size[MAX] ; vector< vector<int> >appear ; bool check(int mid) { priority_queue<int>q ; for(int i = 0 ; i < n ; ++i) { for(int j = 0 ; j < appear[i].size() ; ++j) q.push(appear[i][j]) ; int sz = q.size() ; for(int j = 0 ; j < min(sz , mid) ; ++j) q.pop() ; } for(int j = 0 ; j < appear[n].size() ; ++j) q.push(appear[n][j]) ; for(int i = 0 ; i < m ; ++i) { int sz = q.size() ; for(int j = 0 ; j < min(sz , mid) ; ++j) { int a = q.top() ; if(a >= Size[i]) break; q.pop() ; } } if(q.empty()) return 1 ; return 0 ; } int putaway(int A , int B , int T , int X[] , int Y[] , int W[] , int S[]) { for(int i = 0 ; i < A ; ++i) Weight[i] = X[i] ; for(int i = 0 ; i < B ; ++i) Size[i] = Y[i] ; sort(Weight , Weight + A) ; sort(Size , Size + B) ; n = A , m = B ; appear.resize(A+1) ; for(int i = 0 ; i < T ; ++i) { int idx1 = upper_bound(Weight , Weight + A , W[i]) - Weight ; int idx2 = upper_bound(Size , Size + B , S[i]) - Size ; if(idx1 == A && idx2 == B) return -1 ; appear[idx1].push_back(S[i]) ; } reverse(Size , Size + B) ; for(int i = 0 ; i <= n ; ++i) { if(appear[i].size() == 0) continue; sort(appear[i].begin() , appear[i].end() , greater<int>()); } int l = 1 , r = T , ans; while(l <= r) { int mid = (l + r) / 2 ; if(check(mid)) r = mid-1 , ans = mid; else l = mid+1 ; } return ans ; } /*int main() { int A , B , T ; cin>>A>>B>>T ; int W[T] , S[T] , X[A] , Y[B] ; 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) ; return 0 ; }*/

Compilation message (stderr)

robots.cpp: In function 'bool check(int)':
robots.cpp:19:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0 ; j < appear[i].size() ; ++j)
                         ~~^~~~~~~~~~~~~~~~~~
robots.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0 ; j < appear[n].size() ; ++j)
                     ~~^~~~~~~~~~~~~~~~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:68:25: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int l = 1 , r = T , ans;
                         ^~~
#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...