Submission #964952

# Submission time Handle Problem Language Result Execution time Memory
964952 2024-04-17T19:02:05 Z Acanikolic Robots (IOI13_robots) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
		 		
//#define int long long 
		 
#define pb push_back 
		
#define F first
		 
#define S second
		 
using namespace std;
		 
const int N = 1000000 + 10;
		 
const int mod = 1e9 + 7;
		 
const int inf = 1e9; 	

bool check(int A,int B,int T,vector<int>X,vector<int>Y,vector<pair<int,int>>W,vector<pair<int,int>>S,int mid) {
	vector<bool>vis(T,false);
	priority_queue<int>pq;
	int ptr = -1;
	for(int i = 0; i < T; i++) {
		if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
			for(int j = 0; j < mid; j++) {
				pq.push(X[ptr + 1]);
			}
			ptr += 1;
		}
		if(mid == 3 && i == 1) {
			//cout << "debug:" << X[ptr + 1] << " " << W[i].F << " " << W[i].S << endl; 
		}
		if(pq.empty()) continue;
		vis[W[i].S] = true;
		pq.pop();
	}
	if(mid == 3) {
		//for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
		//cout << endl;
	}
	while(pq.size()) pq.pop();
	ptr = -1;
	for(int i = 0; i < T; i++) {
		if(vis[S[i].S]) continue;
		if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
			for(int j = 0; j < mid; j++) {
				pq.push(Y[ptr + 1]);
			}
			ptr += 1;
		}
		if(pq.empty()) continue;
		vis[S[i].S] = true;
		pq.pop();
	}
	bool ok = true;
	for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
	if(mid == 3) {
	//	for(int i = 0; i < T; i++) if(vis[i]) cout << "dbg:::" << i << endl;
	}
	if(ok) return true;
	while(pq.size()) pq.pop();
	for(int i = 0; i < T; i++) vis[i] = false;
	ptr = -1;
	for(int i = 0; i < T; i++) {
		if(pq.empty() && ptr + 1 < B && Y[ptr + 1] > S[i].F) {
			for(int j = 0; j < mid; j++) {
				pq.push(Y[ptr + 1]);
			}
			ptr += 1;
		}
		if(pq.empty()) continue;
		vis[S[i].S] = true;
		pq.pop();
	}
	while(pq.size()) pq.pop();
	ptr = -1;
	for(int i = 0; i < T; i++) {
		if(vis[W[i].S]) continue;
		if(pq.empty() && ptr + 1 < A && X[ptr + 1] > W[i].F) {
			for(int j = 0; j < mid; j++) {
				pq.push(X[ptr + 1]);
			}
			ptr += 1;
		}
		if(pq.empty()) continue;
		vis[W[i].S] = true;
		pq.pop();
	}
	ok = true;
	for(int i = 0; i < T; i++) if(!vis[i]) ok = false;
	return ok;
} 

int putaway(int A,int B,int T,vector<int>X,vector<int>Y,vector<int>W,vector<int>S) {
	vector<pair<int,int>>w(T);
	vector<pair<int,int>>s(T);
	for(int i = 0; i < T; i++) {
		w[i] = {W[i],i};
		s[i] = {S[i],i};
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	sort(w.begin(),w.end());
	sort(s.begin(),s.end());
	reverse(X.begin(),X.end());
	reverse(Y.begin(),Y.end());
	reverse(w.begin(),w.end());
	reverse(s.begin(),s.end());
	int l = 1, r = max(A,B),ans = -1;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(check(A,B,T,X,Y,w,s,mid)) {
			ans = mid;
			r = mid - 1;
		}else {
			l = mid + 1;
		}
	}
	return ans;
} 
	 		 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	int t;
	cin >> t;
	vector<int>w(t),s(t);
	for(int i = 0; i < t; i++) cin >> w[i] >> s[i];
	int a;
	cin >> a;
	vector<int>x(a);
	for(int i = 0; i < a; i++) cin >> x[i];
	int b;
	cin >> b;
	vector<int>y(b);
	for(int i = 0; i < b; i++) cin >> y[i];
	cout << putaway(a,b,t,x,y,w,s);
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccvDJBZI.o: in function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDZLadF.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccDZLadF.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status