Submission #815806

# Submission time Handle Problem Language Result Execution time Memory
815806 2023-08-08T23:49:10 Z Lobo Highway Tolls (IOI18_highway) C++17
51 / 100
206 ms 18896 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define int long long
const int inf = 1e18+10;
const int maxn = 9e4+10;

int n, m, par[maxn];
vector<int> parid[maxn];
vector<int> g[maxn];

void find_pair(int32_t N, std::vector<int32_t> U, std::vector<int32_t> V, int32_t A, int32_t B) {
	n = N;
	m = U.size();
	for(int i = 0; i < m; i++) {
		g[U[i]].pb(i);
		g[V[i]].pb(i);
	}
	vector<int32_t> vectudoa(m,0);
	int tudoa = ask(vectudoa);
	int path = tudoa/A;

	int edgein = -1;
	int lbs,rbs;
	vector<int32_t> vectoll(m,0);
	lbs = 0;
	rbs = m-1;
	while(lbs <= rbs) {
		int mid = (lbs+rbs)/2;
		vectoll.clear(); vectoll.resize(m,0);
		for(int i = 0; i <= mid; i++) {
			vectoll[i] = 1;
		}

		int toll = ask(vectoll);

		if(toll != tudoa) {
			edgein = mid;
			rbs = mid-1;
		}
		else {
			lbs = mid+1;
		}
	}

	assert(edgein != -1);

	int ss = U[edgein];
	int tt = V[edgein];

	vector<pair<int,int>> d(n+10,mp(inf,0));
	d[ss] = mp(0,ss); par[ss] = -1;
	d[tt] = mp(0,tt); par[tt] = -1;

	queue<int> q; q.push(ss); q.push(tt);
	while(q.size()) {
		int u = q.front(); q.pop();

		for(auto id : g[u]) {
			int v = U[id]+V[id]-u;
			if(d[v].fr > d[u].fr+1) {
				d[v] = mp(d[u].fr+1,d[u].sc);
				par[v] = u;
				parid[v].clear(); parid[v].pb(id);
				q.push(v);
			}
			else if(d[v].fr == d[u].fr+1 && d[v].sc != d[u].sc) {
				d[v].sc = -1;
			}
			else if(d[v].fr == d[u].fr+1) {
				parid[v].pb(id);
			}
		}
	}

	int toll0;

	vector<pair<int,int>> Ds;
	for(int i = 0; i < n; i++) {
		if(d[i].sc == ss) {
			Ds.pb(mp(d[i].fr,i));
		}
	}
	sort(all(Ds));
	lbs = 0;
	rbs = (int) Ds.size()-1;
	int32_t s = ss;

	vectoll.clear(); vectoll.resize(m,1);
	for(int i = 0; i < (int) Ds.size(); i++) {
		for(auto id : parid[Ds[i].sc]) vectoll[id] = 0;
		// if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 1;
	}
	toll0 = ask(vectoll);

	while(lbs <= rbs) {
		int mid = (lbs+rbs)/2;

		vectoll.clear(); vectoll.resize(m,0);

		// for(int i = 0; i <= mid; i++) {
		// 	if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 0;
		// }

		for(int i = mid; i < (int) Ds.size(); i++) {
			for(auto id : parid[Ds[i].sc]) vectoll[id] = 1;
			// if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 1;
		}

		int toll = ask(vectoll);

		if(toll != tudoa) {
			s = Ds[mid].sc;
			lbs = mid+1;
		}
		else {
			rbs = mid-1;
		}
	}

	vector<pair<int,int>> Dt;
	for(int i = 0; i < n; i++) {
		if(d[i].sc == tt) {
			Dt.pb(mp(d[i].fr,i));
		}
	}
	sort(all(Dt));
	lbs = 0;
	rbs = (int) Dt.size()-1;
	int32_t t = tt;

	vectoll.clear(); vectoll.resize(m,1);
	for(int i = 0; i < (int) Dt.size(); i++) {
		for(auto id : parid[Dt[i].sc]) vectoll[id] = 0;
		// if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 1;
	}
	toll0 = ask(vectoll);

	while(lbs <= rbs) {
		int mid = (lbs+rbs)/2;

		vectoll.clear(); vectoll.resize(m,0);

		// for(int i = 0; i <= mid; i++) {
		// 	if(parid[Dt[i].sc] != -1) vectoll[parid[Dt[i].sc]] = 0;
		// }

		for(int i = mid; i < Dt.size(); i++) {
			for(auto id : parid[Dt[i].sc]) vectoll[id] = 1;
			// if(parid[Dt[i].sc] != -1) vectoll[parid[Dt[i].sc]] = 1;
		}

		int toll = ask(vectoll);

		if(toll != tudoa) {
			t = Dt[mid].sc;
			lbs = mid+1;
		}
		else {
			rbs = mid-1;
		}
	}

	// cout << ss << " " << tt << endl;
	// cout << s << " " << t << endl;
	answer(s,t);
}

Compilation message

highway.cpp: In function 'void find_pair(int32_t, std::vector<int>, std::vector<int>, int32_t, int32_t)':
highway.cpp:153:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |   for(int i = mid; i < Dt.size(); i++) {
      |                    ~~^~~~~~~~~~~
highway.cpp:26:6: warning: unused variable 'path' [-Wunused-variable]
   26 |  int path = tudoa/A;
      |      ^~~~
highway.cpp:81:6: warning: variable 'toll0' set but not used [-Wunused-but-set-variable]
   81 |  int toll0;
      |      ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4560 KB Output is correct
5 Correct 3 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 2 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4592 KB Output is correct
2 Correct 12 ms 6020 KB Output is correct
3 Correct 112 ms 17048 KB Output is correct
4 Correct 105 ms 17152 KB Output is correct
5 Correct 145 ms 17032 KB Output is correct
6 Correct 120 ms 17124 KB Output is correct
7 Correct 142 ms 17144 KB Output is correct
8 Correct 133 ms 17224 KB Output is correct
9 Correct 127 ms 17052 KB Output is correct
10 Correct 140 ms 17032 KB Output is correct
11 Correct 115 ms 16732 KB Output is correct
12 Correct 112 ms 16476 KB Output is correct
13 Correct 105 ms 16544 KB Output is correct
14 Correct 127 ms 16476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5968 KB Output is correct
2 Correct 22 ms 7168 KB Output is correct
3 Correct 27 ms 8464 KB Output is correct
4 Correct 91 ms 16452 KB Output is correct
5 Correct 92 ms 16404 KB Output is correct
6 Correct 73 ms 16744 KB Output is correct
7 Correct 74 ms 16552 KB Output is correct
8 Correct 73 ms 15964 KB Output is correct
9 Correct 102 ms 16504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4560 KB Output is correct
2 Correct 12 ms 5984 KB Output is correct
3 Correct 94 ms 14780 KB Output is correct
4 Correct 146 ms 17020 KB Output is correct
5 Correct 163 ms 17060 KB Output is correct
6 Correct 113 ms 17020 KB Output is correct
7 Correct 145 ms 17108 KB Output is correct
8 Correct 141 ms 17008 KB Output is correct
9 Correct 150 ms 17052 KB Output is correct
10 Correct 134 ms 17044 KB Output is correct
11 Correct 156 ms 16552 KB Output is correct
12 Correct 139 ms 16764 KB Output is correct
13 Correct 142 ms 16560 KB Output is correct
14 Correct 144 ms 16332 KB Output is correct
15 Correct 121 ms 17124 KB Output is correct
16 Correct 126 ms 17048 KB Output is correct
17 Correct 121 ms 16572 KB Output is correct
18 Correct 134 ms 16492 KB Output is correct
19 Correct 116 ms 17108 KB Output is correct
20 Correct 136 ms 16608 KB Output is correct
21 Correct 118 ms 17908 KB Output is correct
22 Correct 96 ms 17936 KB Output is correct
23 Correct 111 ms 17660 KB Output is correct
24 Correct 106 ms 17560 KB Output is correct
25 Correct 131 ms 16600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 6004 KB Output is correct
2 Correct 12 ms 6156 KB Output is correct
3 Correct 150 ms 17488 KB Output is correct
4 Correct 125 ms 17468 KB Output is correct
5 Correct 158 ms 18896 KB Output is correct
6 Correct 206 ms 17916 KB Output is correct
7 Correct 193 ms 17952 KB Output is correct
8 Incorrect 148 ms 18240 KB Output is incorrect: {s, t} is wrong.
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5900 KB Output is correct
2 Correct 18 ms 6152 KB Output is correct
3 Correct 160 ms 16904 KB Output is correct
4 Correct 127 ms 16992 KB Output is correct
5 Correct 145 ms 17108 KB Output is correct
6 Correct 162 ms 18160 KB Output is correct
7 Correct 161 ms 17604 KB Output is correct
8 Correct 123 ms 17724 KB Output is correct
9 Incorrect 149 ms 17408 KB Output is incorrect: {s, t} is wrong.
10 Halted 0 ms 0 KB -