Submission #945029

#TimeUsernameProblemLanguageResultExecution timeMemory
945029oblantisRobots (IOI13_robots)C++17
90 / 100
3078 ms25704 KiB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = INT_MAX;
const int mod = 1e9+7;
const int maxn = 5002;
#include "robots.h"

int putaway(int a, int b, int t, int x[], int y[], int w[], int s[]) {
	int l = 0, r = t + 1;
	vt<pii> v;
	int hmt[b + 1], tor[b + 1];
	hmt[b] = 0, tor[b] = b;
	set<int> S;
	for(int i = 0; i < b; i++){
		S.insert(y[i]);
	}
	map<int, int> toc;
	int id = 0;
	for(auto i : S)toc[i] = id++;
	for(int i = 0; i < a; i++){
		v.pb({x[i] - 1, inf});
	}
	for(int i = 0; i < t; i++){
		if(S.upper_bound(s[i]) == S.end())s[i] = b;
		else s[i] = toc[*S.upper_bound(s[i])];
		v.pb({w[i], s[i]});
	}
	sort(all(v));
	while(l + 1 < r){
		int mid = l + (r - l) / 2;
		for(int i = 0; i < b; i++){
			hmt[i] = mid;
			tor[i] = i;
		}
		priority_queue<int, vt<int>, greater<int>> pq;
		bool ok = 1;
		for(int i = t + a - 1, cnt = 0; i >= 0; i--){
			if(v[i].ss == inf){
				cnt += mid;
			}
			else {
				pq.push(v[i].ss);
				if(cnt)cnt--;
				else {
					int nw = pq.top();
					pq.pop();
					while(tor[nw] != nw)nw = tor[nw];
					if(nw == b){
						ok = 0;
						break;
					}
					hmt[nw]--;
					if(hmt[nw] == 0)tor[nw] = tor[nw + 1];
				}
			}
		}
		if(ok)r = mid;
		else l = mid;
	}
	if(r > t)return -1;
	return r;
}

//int main() {
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	//int a, b, t;
	//cin >> a >> b >> t;
	//int x[a], y[b], w[t], s[t];
	//for(int i = 0; i < a; i++)cin >> x[i];
	//for(int i = 0; i < b; i++)cin >> y[i];
	//for(int i = 0; i < t; i++)cin >> w[i] >> s[i];
	//cout << putaway(a, b, t, x, y, w, s);

	//return 0;
//}

#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...