Submission #587157

#TimeUsernameProblemLanguageResultExecution timeMemory
587157yutabiRobots (IOI13_robots)C++14
100 / 100
1718 ms31236 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; #define pb push_back typedef pair <int,int> ii; typedef pair <ii,int> iii; int putaway(int A, int B, int N, int X[], int Y[], int W[], int S[]) { vector <iii> items; vector <ii> x; vector <ii> y; vector <int> w; vector <int> s; for(int i=0;i<N;i++) { items.pb(iii(ii(W[i],S[i]),i)); x.pb(ii(W[i],i)); y.pb(ii(S[i],i)); } for(int i=0;i<A;i++) { w.pb(X[i]); } for(int i=0;i<B;i++) { s.pb(Y[i]); } sort(items.begin(),items.end()); sort(x.begin(),x.end()); sort(y.begin(),y.end()); sort(w.begin(),w.end()); sort(s.begin(),s.end()); /*for(int i=0;i<N;i++) { printf("%d %d %d\n",items[i].first.first,items[i].first.second,items[i].second); } printf("\n"); for(int i=0;i<N;i++) { printf("%d %d\n",x[i].first,x[i].second); } printf("\n"); for(int i=0;i<N;i++) { printf("%d %d\n",y[i].first,y[i].second); } printf("\n"); for(int i=0;i<A;i++) { printf("%d\n",w[i]); } printf("\n"); for(int i=0;i<B;i++) { printf("%d\n",s[i]); } printf("\n");*/ int l=1; int r=N+2343; while(l!=r) { int m=(l+r)/2; vector <bool> taken(N,0); priority_queue <ii> pq; int ptr1=0,ptr2=0; for(;ptr1<A;ptr1++) { while(ptr2<N && items[ptr2].first.first<w[ptr1]) { pq.push(ii(items[ptr2].first.second,items[ptr2].second)); ptr2++; } for(int i=0;i<m && pq.size();i++) { taken[pq.top().second]=1; pq.pop(); } } ptr1=B-1; ptr2=N-1; for(;ptr1>=0 && ptr2>=0;ptr1--) { for(int left=m;ptr2>=0 && left;ptr2--) { if(taken[y[ptr2].second]==0) { if(s[ptr1]<=y[ptr2].first) { break; } taken[y[ptr2].second]=1; left--; } } } bool flag=0; for(int i=0;i<N;i++) { if(taken[i]==0) { flag=1; } } if(flag) { l=m+1; } else { r=m; } } if(r>N) { return -1; } 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...