Submission #120904

# Submission time Handle Problem Language Result Execution time Memory
120904 2019-06-25T17:18:33 Z Sorting Highway Tolls (IOI18_highway) C++14
0 / 100
1500 ms 6016 KB
#include <bits/stdc++.h>
#include "highway.h"
 
using namespace std;
 
const int MAXN = 1e5 + 7;
 
long long ask(const vector<int> &w);
void answer(int s, int t);
 
mt19937 mt();
 
long long n, m;
vector<int> adj[MAXN], idx[MAXN], w;
bool used[MAXN];

long long a, b;
long long sm;
 
vector<pair<int, int> > bfs(int x){
	queue<int> q;
 
	for(int i = 0; i < n; i++){
		used[i] = false;
	}
 
	q.push(x);
	
	vector<pair<int, int> > v;
 
	while(!q.empty()){
		int u = q.front();
		q.pop();
 
		if(used[u]){
			continue;
		}
		used[u] = true;
 
		for(int i = 0; i < adj[u].size(); i++){
			int to = adj[u][i];
			int j = idx[u][i];
 
			if(!used[to]){
				q.push(to);
				v.push_back({j, to});
			}
		}
	}
 
	return v;
}
 
int away(int x, const vector<int> &U, const vector<int> &V){
	vector<pair<int, int> > v = bfs(x);
 
	while((int)v.size() == m);

	int l = 0, r = (int)v.size() - 1;
 
	while(l != r){
		int mid = (l + r) >> 1;
		 
		for(int i = 0; i < m; i++){
			w[i] = 0;
		}

		for(int i = 0; i <= mid; i++){
			w[ v[i].first ] = 1;
		}

		long long score = ask(w);

		if(score == (sm / a) * b){
			r = mid;
		}
		else{
			l = mid + 1;
		}
	}

	return v[l].second;
}
 
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
	n = N;
	m = U.size();
 
	for(int i = 0; i < m; i++){
		adj[V[i]].push_back(U[i]);
		adj[U[i]].push_back(V[i]);
 
		idx[V[i]].push_back(i);
		idx[U[i]].push_back(i);
		w.push_back(0);
	}
 
	sm = ask(w);
	a = A;
	b = B;
 
	int l = 0, r = m - 1;
 
	while(l != r){
		int mid = (l + r) / 2;
 
		for(int i = 0; i < m; i++){
			w[i] = 0; 
		}
		for(int i = mid + 1; i <= r; i++){
			w[i] = 1;
		}
 
		long long score = ask(w);
		score -= sm;
 
		if(score){
			l = mid + 1;
		}
		else{
			r = mid;
		}
	}
 
	int x, y;
 
	x = away(U[l], U, V);
 
	y = away(x, U, V);
 
	answer(x, y);
}
/*
9 1 2
4 8
4 2
8 0
2 5
2 7
2 3
0 1
0 6
*/

Compilation message

highway.cpp: In function 'std::vector<std::pair<int, int> > bfs(int)':
highway.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < adj[u].size(); i++){
                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3019 ms 5020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3009 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 5984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3049 ms 5104 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3082 ms 6016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3031 ms 6012 KB Time limit exceeded
2 Halted 0 ms 0 KB -