제출 #426371

#제출 시각아이디문제언어결과실행 시간메모리
426371frodakcin로봇 (IOI13_robots)C++17
0 / 100
3071 ms280 KiB
#include "robots.h" #include <cassert> #include <algorithm> #include <map> #include <vector> #include <numeric> #include <functional> int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { std::sort(X, X+A); std::sort(Y, Y+B); for(int i=0;i<T;++i) if((A==0||W[i]>=X[A-1]) && (B==0||S[i]>=Y[B-1])) return -1; for(int i=0;i<T;++i) { W[i] = std::lower_bound(X, X+A, W[i])-X; S[i] = std::lower_bound(Y, Y+B, S[i])-Y; } //must be possible; std::vector<int> ord(T); std::iota(ord.begin(), ord.end(), 0); std::sort(ord.begin(), ord.end(), [&](int u, int v){return W[u]<W[v];}); int l=0, r=T; for(;r-l>1;) { int m=l+(r-l)/2; int j=0; std::map<int, int> map; for(int i=0;i<=A;++i) { for(;j < T && W[ord[j]] == i;++j) ++map[S[ord[j]]]; if(i<A) for(int rem=m;rem>0 && !map.empty();) { auto it=std::prev(map.end()); if(rem >= it->second) rem -= it->second, map.erase(it); else it->second -= rem, rem=0; } } int c=0; for(int i=0;i<=B;++i) { if(map.begin()->first == i) c += map.begin()->second, map.erase(map.begin()); if(i<B) c=std::max(c-m, 0); } if(c==0) // good r=m; else l=m; } return r; }
#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...