Submission #592472

#TimeUsernameProblemLanguageResultExecution timeMemory
592472fuad27Robots (IOI13_robots)C++17
90 / 100
3073 ms51544 KiB
#include "robots.h" #include<bits/stdc++.h> using namespace std; int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { if(B == 0) { sort(X, X+A); int lo = 0, hi = 2*A; int res=-1; while(lo <= hi) { int mid = (lo+hi)/2; vector<int> v(A); for(int i = 0;i<T;i++) { int it = upper_bound(X, X+A, W[i])-X; if(it == A)return -1; v[it]++; } for(int i = 0;i<A-1;i++) { if(v[i] > mid) { v[i+1]+=v[i]-mid; v[i]=mid; } } if(v.back() > mid) { lo = mid+1; } else { res=mid; hi=mid-1; } } return res; } sort(X, X+A); sort(Y, Y+B); int lo = 1, hi = T; int res=-1; while(lo <= hi) { int mid = (lo+hi)/2; multiset<int> v[A]; multiset<int> rem2; for(int i = 0;i<T;i++) { int it = upper_bound(X, X+A, W[i])-X; if(it == A)rem2.insert(S[i]); else v[it].insert(S[i]); } multiset<int> rem; for(int i = 0;i<A;i++) { while(v[i].size() > mid) { auto it = v[i].begin(); rem.insert(*it); v[i].erase(it); } while(rem.size()>0 and v[i].size() < mid) { auto it = rem.end(); --it; v[i].insert(*it); rem.erase(it); } while(rem.size() and v[i].size() and (*(--rem.end())) > (*v[i].begin())) { auto it = (--rem.end()); auto it2 = v[i].begin(); v[i].insert(*it); rem.insert(*it2); rem.erase(it); v[i].erase(it2); } } for(auto it=rem2.begin();it!=rem2.end();it++) { rem.insert(*it); } vector<int> v2(B); for(auto it=rem.begin();it!=rem.end();++it) { int val = (*it); int idx=upper_bound(Y, Y+B, val)-Y; if(idx==B)return -1; v2[idx]++; } for(int i = 0;i<B-1;i++) { if(v2[i] > mid) { int c = v2[i]-mid; v2[i+1]+=c; v2[i]=mid; } } if(v2.back() > mid) { lo = mid+1; } else { res=mid; hi = mid-1; } } return res; }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:48:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |    while(v[i].size() > mid) {
      |          ~~~~~~~~~~~~^~~~~
robots.cpp:53:39: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |    while(rem.size()>0 and v[i].size() < mid) {
      |                           ~~~~~~~~~~~~^~~~~
#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...