Submission #784214

# Submission time Handle Problem Language Result Execution time Memory
784214 2023-07-15T21:15:51 Z APROHACK Highway Tolls (IOI18_highway) C++14
12 / 100
128 ms 13304 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;
int m, n;
vector<int>adj[100000];
vector<int>idx[100000];
vector<int>options;
vector<int>edjes;
bool vis[100000];
ll largo;
void bfs(int s){
	memset(vis, false, sizeof vis);
	int distancia[100000];
	queue<int>cola;
	distancia[0] = 0;
	vis[0] = true;
	cola.push(s);
	while(!cola.empty()){
		int cur = cola.front();
		//cout << cur << endl;
		cola.pop();
		for(int i = 0 ; i < adj[cur].size() ; i ++){
			if(vis[adj[cur][i]])continue;
			vis[adj[cur][i]] = true;
			distancia[adj[cur][i]] = distancia[cur] + 1;
			if(distancia[adj[cur][i]] == largo){
				options.pb(adj[cur][i]);
				edjes.pb(idx[cur][i]);
			}
			cola.push(adj[cur][i]);
		}
	}
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	m = U.size();
	n = N;
	bool val = true;
	for(int i = 0 ; i < m ; i ++){
		adj[U[i]].pb(V[i]);
		adj[V[i]].pb(U[i]);
		idx[U[i]].pb(i);
		idx[V[i]].pb(i);
		if(U[i] != i)val = false;
		if(V[i] != i + 1)val = false;
	}
	vector<int>w;
	for(int i = 0 ; i < m ; i ++)w.pb(0);
	ll ans = ask(w);
	largo = ans / A;
	if(val){
		int ansA, ansB;
		int li = 0, ls = m-1, pos;
		pos = (li + ls )/2;
		while(li+1 < ls){
			for(int i = 0 ; i < m ; i ++)w[i] = 0;
			for(int i = pos ; i <= ls ; i ++){
				w[i] = 1;
			}
			if(ask(w) > largo*A){
				li = pos;
			}else{
				ls = pos -1;
			}
			pos = (li + ls)/2;
		}
		for(int i = 0 ; i < m ; i ++)w[i] = 0;
		w[ls] = 1;
		if(ask(w) > largo*A){
			ansA = V[ls];
		}else ansA = V[li];
		
		
		li = 0, ls = m-1, pos;
		pos = (li + ls )/2;
		while(li+1 < ls){
			for(int i = 0 ; i < m ; i ++)w[i] = 0;
			for(int i = li ; i <= pos ; i ++){
				w[i] = 1;
			}
			if(ask(w) > largo*A){
				ls = pos;
			}else{
				ls = pos +1;
			}
			pos = (li + ls)/2;
		}
		for(int i = 0 ; i < m ; i ++)w[i] = 0;
		w[li] = 1;
		if(ask(w) > largo*A){
			ansB = U[li];
		}else ansB = U[ls];
		answer(ansA, ansB);
	}else{

		bfs(0);
		int li = 0, ls = options.size()-1;
		int pos = (li + ls)/2;
		while(li + 1 < ls){
			for(int i = 0 ; i < m ; i ++)w[i] = 0;
			for(int i = pos ; i <= ls ; i ++)w[edjes[i]] = 1;
			if(ask(w) > largo*A){
				li = pos;
			}else{
				ls = pos -1;
			}
			pos = (li + ls )/2;
		}
		for(int i = 0 ;  i < m ; i ++)w[i] = 0;
		w[edjes[li]] = 1;
		if(ask(w) > largo*A)answer(0, options[li]);
		else answer(0, options[ls]);
	}
}

Compilation message

highway.cpp: In function 'void bfs(int)':
highway.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for(int i = 0 ; i < adj[cur].size() ; i ++){
      |                   ~~^~~~~~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:78:24: warning: right operand of comma operator has no effect [-Wunused-value]
   78 |   li = 0, ls = m-1, pos;
      |                        ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5404 KB Output is correct
2 Correct 3 ms 5456 KB Output is correct
3 Correct 3 ms 5396 KB Output is correct
4 Correct 3 ms 5456 KB Output is correct
5 Correct 3 ms 5456 KB Output is correct
6 Correct 2 ms 5400 KB Output is correct
7 Correct 3 ms 5364 KB Output is correct
8 Correct 3 ms 5400 KB Output is correct
9 Correct 3 ms 5456 KB Output is correct
10 Correct 3 ms 5396 KB Output is correct
11 Correct 3 ms 5456 KB Output is correct
12 Correct 2 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5456 KB Output is correct
2 Correct 9 ms 6360 KB Output is correct
3 Correct 75 ms 13300 KB Output is correct
4 Correct 104 ms 13304 KB Output is correct
5 Correct 77 ms 13300 KB Output is correct
6 Correct 115 ms 13176 KB Output is correct
7 Correct 90 ms 13112 KB Output is correct
8 Correct 90 ms 13236 KB Output is correct
9 Correct 128 ms 13120 KB Output is correct
10 Correct 121 ms 13236 KB Output is correct
11 Correct 73 ms 12996 KB Output is correct
12 Correct 90 ms 13004 KB Output is correct
13 Correct 84 ms 12968 KB Output is correct
14 Correct 85 ms 12908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 5840 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5456 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 6352 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 6352 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -