Submission #963588

#TimeUsernameProblemLanguageResultExecution timeMemory
963588simona1230Robots (IOI13_robots)C++17
100 / 100
1730 ms38624 KiB
#include <bits/stdc++.h> #include "robots.h" using namespace std; int a,b,t,x[50000],y[50000]; pair<int,int> w[1000000],s[1000000]; int wg[1000000],sz[1000000]; struct edge { int w,s,id; edge(){} edge(int _w,int _s,int i) { w=_w; s=_s; id=i; } bool operator<(const edge&e)const { return e.s>s; } }; priority_queue<edge> q; int used[1000000]; bool smart(int k) { //cout<<k<<" * "<<endl; memset(used,0,sizeof(used)); int id=0,in=0; for(int i=0;i<a;i++) { int cnt=0; while(id<t&&w[id].first<x[i]) { int idx=w[id].second; q.push({wg[idx],sz[idx],idx}); id++; } //cout<<i<<"-"<<endl; while(cnt<k&&q.size()) { int t=q.top().id; //cout<<"/ "<<t<<" "<<wg[t]<<" "<<sz[t]<<endl; q.pop(); cnt++; used[t]=1; in++; } } //cout<<"pout"<<endl; id=0; for(int i=0;i<b;i++) { int cnt=0; while(id<t&&s[id].first<y[i]&&cnt<k) { int idx=s[id].second; if(!used[idx]) { cnt++; used[idx]=1; in++; } id++; } } /*for(int i=0;i<t;i++) cout<<used[i]<<" "; cout<<endl;*/ while(q.size())q.pop(); if(in==t)return 1; return 0; } // sort by s in pq, sort by w in va int putaway(int A,int B,int T,int X[],int Y[],int W[],int S[]) { a=A; b=B; t=T; for(int i=0;i<a;i++) x[i]=X[i]; for(int i=0;i<b;i++) y[i]=Y[i]; for(int i=0;i<t;i++) w[i].first=W[i],s[i].first=S[i],w[i].second=s[i].second=i,wg[i]=W[i],sz[i]=S[i]; sort(x,x+a); sort(y,y+b); sort(w,w+t); sort(s,s+t); int l=1,r=t; int ans=-1; while(l<=r) { int m=(l+r)/2; if(smart(m)) { ans=m; r=m-1; } else l=m+1; } return 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...