Submission #184079

#TimeUsernameProblemLanguageResultExecution timeMemory
184079arman_ferdousRobots (IOI13_robots)C++17
0 / 100
7 ms376 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;

struct ds{
	multiset<pair<int,int>> st;
	void insert(int x, int y) {
		st.insert({x, y});
	}
	void remove(int x, int y) {
		st.erase({x, y});
	}
	pair<int,int> find(int x) {
		auto it = st.lower_bound({x, -1});
		if(it == st.begin()) return {-1, -1};
		it--; return {it->first, it->second};
	}
}one, two;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
	sort(X, X + A);
	sort(Y, Y + B);
    for(int i = 0; i < T; i++) {
    	one.insert(W[i], S[i]);
    	two.insert(S[i], W[i]);
    }
    int ans = 0, sz = T;
    while(!one.st.empty()) {
    	vector<pair<int,int>> way1, way2;
    	for(int i = A - 1; i >= 0 && !one.st.empty(); i--) {
    		auto got = one.find(X[i]);
    		if(got.first == -1) break;
    		way1.push_back({got.first, got.second});
    		one.remove(got.first, got.second);
    		two.remove(got.second, got.first);
    	}
    	for(int i = B - 1; i >= 0 && !one.st.empty(); i--) {
    		auto got = two.find(Y[i]);
    		if(got.first == -1) break;
    		way1.push_back({got.first, got.second});
    		two.remove(got.first, got.second);
    		one.remove(got.second, got.first);
    	}
    	if(way1.empty()) { ans = -1; break; }
    	for(auto it : way1) {
    		one.insert(it.first, it.second);
    		two.insert(it.first, it.second);
    	}

    	for(int i = B - 1; i >= 0 && !one.st.empty(); i--) {
    		auto got = two.find(Y[i]);
    		if(got.first == -1) break;
    		way2.push_back({got.first, got.second});
    		two.remove(got.first, got.second);
    		one.remove(got.second, got.first);
    	}
    	for(int i = A - 1; i >= 0 && !one.st.empty(); i--) {
    		auto got = one.find(X[i]);
    		if(got.first == -1) break;
    		way2.push_back({got.first, got.second});
    		one.remove(got.first, got.second);
    		two.remove(got.second, got.first);
    	}
    	for(auto it : way2) {
    		one.insert(it.first, it.second);
    		two.insert(it.first, it.second);
    	}
    	ans++;
    	if((int)way1.size() > (int)way2.size()) {
    		for(auto it : way1) {
    			one.remove(it.first, it.second);
    			two.remove(it.first, it.second);
    		}
    	} else for(auto it : way2) {
    		one.remove(it.first, it.second);
    		two.remove(it.first, it.second);
    	}
    }
    return ans;
}

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:27:18: warning: unused variable 'sz' [-Wunused-variable]
     int ans = 0, sz = T;
                  ^~
#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...