Submission #598472

#TimeUsernameProblemLanguageResultExecution timeMemory
598472Koosha_mvRobots (IOI13_robots)C++14
39 / 100
750 ms59152 KiB
#include "robots.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=1e6+99,inf=2e9+99; int n,m,k,ans,A[N],B[N]; vector<int> X,Y; vector<pair<int,int>> vec1,vec2; struct segment{ int n; vector<pair<int,int>> seg,vec; void init(vector<pair<int,int>> _vec){ vec=_vec; n=_vec.size(); f(i,0,(n<<1)+10){ seg.pb(mp(-1,-1)); } } void op(int x,int val){ for(x+=n,seg[x]=mp(val,vec[x-n].S);x>1;x>>=1){ seg[x>>1]=max(seg[x],seg[x^1]); //erorp(seg[x>>1]); } } void change(pair<int,int> a,int val){ int p=lower_bound(all(vec),a)-vec.begin(); op(p,val); } int get(int l,int r){ pair<int,int> ans=mp(-1,-1); for(l+=n,r+=n;l<r;l>>=1,r>>=1){ //cout<<l<<" "<<r<<endl; if(l&1){ //eror(l); maxm(ans,seg[l++]); } if(r&1){ maxm(ans,seg[--r]); //eror(r); } } return (ans.F==-1 ? -1 : ans.S); } int get(int x){ int p=upper_bound(all(vec),mp(x,-1))-vec.begin(); return get(0,p); } } seg1,seg2; int putaway(int P1, int P2, int _n, int S[], int T[], int _A[], int _B[]) { n=_n; f(i,0,P1) X.pb(S[i]); f(i,0,P2) Y.pb(T[i]); f(i,0,n){ A[i]=_A[i],B[i]=_B[i]; vec1.pb(mp(A[i],i)); vec2.pb(mp(B[i],i)); } sort(all(X)); sort(all(Y)); sort(all(vec1)); sort(all(vec2)); seg1.init(vec1); seg2.init(vec2); for(auto p : vec1) seg1.change(p,B[p.S]); for(auto p : vec2) seg2.change(p,A[p.S]); for(;(X.size() || Y.size()) && seg1.get(0,n)!=-1 && ans<5;ans++){ vector<int> VX,VY; int b=0; for(auto x : X){ int id=seg1.get(x); //cout<<"X "<<id<<endl; if(id!=-1){ VX.pb(x); b=1; seg1.change(mp(A[id],id),-1); seg2.change(mp(B[id],id),-1); } } for(auto y : Y){ int id=seg2.get(y); if(id!=-1){ //cout<<"Y "<<id<<endl; VY.pb(y); b=1; seg1.change(mp(A[id],id),-1); seg2.change(mp(B[id],id),-1); } } if(b==0){ return -1; } } if(seg1.get(0,n)!=-1){ return -1; } return ans; } /* 3 2 10 6 2 9 4 7 4 6 8 5 2 3 7 9 1 8 5 1 3 3 8 7 7 6 10 5 */
#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...