제출 #80861

#제출 시각아이디문제언어결과실행 시간메모리
80861antimirage로봇 (IOI13_robots)C++17
90 / 100
1972 ms66560 KiB
#include "robots.h"
#include <bits/stdc++.h>
#define mk make_pair
#define fr first
#define sc second

using namespace std;

const int N = 1e6 + 5, M = 5e4 + 5;

int a, b, n, x[M], y[M];

pair <int, int> ar[N];

inline bool check(int k)
{
	priority_queue <int> q;
	
	int j = 0, cn = 0;
	for (int i = 0; i < a; i++)
	{
		while ( j < n && ar[j].fr < x[i] )
			q.push( ar[j].sc ), j++;
	
		cn = 0;
		while ( !q.empty() && cn < k )
			q.pop(), cn++;
	}
	while (j < n)
		q.push( ar[j].sc ), j++;
		
	for (int i = b - 1; i >= 0; i--)
	{
		cn = 0;
		while (!q.empty() && cn < k && q.top() < y[i])
			q.pop(), cn++;
	}
	if (q.empty())
		return true;
		
	return false;
}
bool fl = 0;

int putaway(int A, int B, int T, int X[], int Y[], int w[], int s[]) 
{
	a = A, b = B;
	n = T;
	for (int i = 0; i < a; i++) x[i] = X[i];
	for (int i = 0; i < b; i++) y[i] = Y[i];
	sort(x, x + a);
	sort(y, y + b);
	
	for (int i = 0; i < n; i++)
	{
		ar[i].fr = w[i], ar[i].sc = s[i];
		if (ar[i].fr >= x[a - 1] && ar[i].sc >= y[b - 1]) fl = 1;
	}
	if (fl) return -1;
	
	sort(ar, ar + n); 
	
	int l = -1, r = n;
	
	while (r - l > 1)
	{
		int md = (l + r) >> 1;
		if ( check(md) )
			r = md;
		else
			l = md;
	}
	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...