제출 #1356194

#제출 시각아이디문제언어결과실행 시간메모리
1356194gvancak로봇 (IOI13_robots)C++20
76 / 100
190 ms28544 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll N=1e6;
int A, B, T, i;
int res;
vector <int> fix(N+5);
pair <int,int> g;
int x,ind;	
int m,k,n;
priority_queue <pair<int,int> > p;
pair <pair <int,int> ,int> pw[N+5],ps[N+5];
int a[N+5],b[N+5],w[N+5],s[N+5];
bool check(long long rd){
	
	for (int i=0; i<n; i++ ) fix[i]=0;

	while (!p.empty()) p.pop();
	ind=0;
	for (int i=0; i<m; i++){
		
		x=a[i];
		while (ind<n && pw[ind].f.f<x){
			if (fix[pw[ind].s]==0)
			p.push(mp(pw[ind].f.s,pw[ind].s));
			ind++;
		}
		
		for (int i=0; i<rd; i++){
			if (p.size()==0) break;
			pair <int,int> g=p.top(); p.pop();
			fix[g.s]=1;
		}
		
	}
	
	while (!p.empty()) p.pop();
	ind=0;
	for (int i=0; i<k; i++){
		
		x=b[i];
		while (ind<n && ps[ind].f.f<x){
			if (fix[ps[ind].s]==0)
			p.push(mp(ps[ind].f.s,ps[ind].s));
			ind++;
		}
		
		for (int i=0; i<rd; i++){
			if (p.size()==0) break;
			pair <int,int> g=p.top(); p.pop();
			fix[g.s]=1;
		}
		
	}
	
	for (int i=0; i<n; i++) if (fix[i]==0) return 0;
	return 1;
	
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
	m=A;k=B;n=T;
	
	for (int i=0; i<m; i++) a[i]=X[i];
	for (int i=0; i<k; i++) b[i]=Y[i];
	for (int i=0; i<n; i++){
		w[i]=W[i]; s[i]=S[i];
	}
	sort(a,a+m);
	sort(b,b+k);
	
	pair <int,int> g;
	for (int i=0; i<n; i++){
		g=mp(w[i],s[i]);
		pw[i]=mp(g,i);
		g=mp(s[i],w[i]);
		ps[i]=mp(g,i);
	}
	/*3 2 10
	6 2 9
	4 7
	4 8 2 7 1 5 3 8 7 10
	6 5 3 9 8 1 3 7 6 5*/
	sort(pw,pw+n);
	sort(ps,ps+n);
	ll mx=n*max(m,k);
	ll lg=log2(mx);
	ll ans=0;
	int pww=1;
	for (int i=1; i<=lg; i++) pww*=2;
	for (int i=lg; i>=0; i--){
		
		if (check(ans+pww)==0) ans+=pww;
		pww/=2;
	}
	if (ans+1>mx) return -1;
	return ans+1;
	
}
#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...