Submission #1058173

# Submission time Handle Problem Language Result Execution time Memory
1058173 2024-08-14T08:50:19 Z ReLice Highway Tolls (IOI18_highway) C++17
90 / 100
151 ms 28732 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define pf push_front
#define sz size()
#define bc back()
#define pob pop_back()
#define pof pop_front()
#define fr first
#define sc second
using namespace std;
const ll N=2e5+7;
const ll inf=1e18;
vector<vector<array<ll,2>>> g(N), g2(N);
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	ll M = V.sz;
	ll s, t, rt;
	ll n = N;
	vll v, u;
	ll i;
	
	for(auto i : V) v.pb(i);
	for(auto i : U) u.pb(i);
	
	vector<int> w(M, 0);
	
	ll x = ask(w);
	
	for(i=0;i<M;i++){
		g[v[i]].pb({u[i], i});
		g[u[i]].pb({v[i], i});
	}
	
	{//getting vertex on the path
		ll l = 0, r = n;
		while(l + 1 < r){
			ll m = (l + r) / 2;
			
			if(r - l > 60000) m = 60000;
			
			w.assign(M, 0);
			
			for(i=0;i<m;i++){
				for(auto [to, r] : g[n - i - 1]) w[r] = 1;
			}
			
			ll y = ask(w);
			
			if(y == x) l = m;
			else r = m;
		}
		
		rt = n - r;
	}
	
	vll p(n), d(n);
	vll pr(n), tour;
	vector<vll> dd(n);
	
	auto bfs = [&](ll s){
		for(i=0;i<n;i++){
			dd[i].clear();
			d[i] = inf;
			pr[i] = p[i] = -1;
		}
		
		queue<ll> q;
		q.push(s);
		d[s] = 0;
		
		while(q.size()){
			ll x = q.front();
			q.pop();
			
			dd[d[x]].pb(x);
			
			for(auto [to, r] : g[x]){
				if(d[to] > d[x] + 1){
					d[to] = d[x] + 1 ;
					pr[to] = r;
					p[to] = x;
					q.push(to);
				}
			}
		}
		
		tour.clear();
		for(i=0;i<n;i++){
			for(auto j : dd[i]) tour.pb(j);
		}
	};
	
	vll path;
	auto calc = [&](ll N){
		ll l = 0, r = N;
		while(l + 1 < r){
			ll m = (l + r) / 2;
			
			if(r - l > 60000) m = 30000;
			
			w.assign(M, 1);
			
			for(auto i : path) w[i] =0;
			
			//~ cout<<m<<endl;
			for(i=1;i<m;i++) {
				w[pr[tour[i]]] = 0;
				//~ cout<<v[pr[tour[i]]]<<' '<<u[pr[tour[i]]]<<endl;
			}
			
			ll y = ask(w);
				
			if(x == y) r = m;
			else l = m;
		}
		
		return r - 1;
	};
	
	bfs(rt);
	
	ll k = calc(n);
	s = tour[k];
	
	{
		ll x = s;
		while(x != rt){
			path.pb(pr[x]);
			x = p[x];
		}
	}
	
	t = tour[calc(k)];
	
	answer(s, t);
}


# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 3 ms 9816 KB Output is correct
3 Correct 3 ms 9816 KB Output is correct
4 Correct 2 ms 9816 KB Output is correct
5 Correct 2 ms 9816 KB Output is correct
6 Correct 2 ms 9816 KB Output is correct
7 Correct 2 ms 9816 KB Output is correct
8 Correct 2 ms 9644 KB Output is correct
9 Correct 2 ms 9816 KB Output is correct
10 Correct 3 ms 9816 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9792 KB Output is correct
2 Correct 10 ms 11504 KB Output is correct
3 Correct 94 ms 24020 KB Output is correct
4 Correct 97 ms 24148 KB Output is correct
5 Correct 96 ms 24112 KB Output is correct
6 Correct 97 ms 24140 KB Output is correct
7 Correct 89 ms 24272 KB Output is correct
8 Correct 88 ms 24008 KB Output is correct
9 Correct 90 ms 24036 KB Output is correct
10 Correct 103 ms 24148 KB Output is correct
11 Correct 98 ms 24400 KB Output is correct
12 Correct 106 ms 24648 KB Output is correct
13 Correct 95 ms 24368 KB Output is correct
14 Correct 103 ms 24356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11444 KB Output is correct
2 Correct 20 ms 13064 KB Output is correct
3 Correct 26 ms 14800 KB Output is correct
4 Correct 82 ms 24396 KB Output is correct
5 Correct 75 ms 24524 KB Output is correct
6 Correct 67 ms 25700 KB Output is correct
7 Correct 69 ms 25672 KB Output is correct
8 Correct 78 ms 24628 KB Output is correct
9 Correct 79 ms 25016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 11 ms 11456 KB Output is correct
3 Correct 63 ms 21256 KB Output is correct
4 Correct 84 ms 24192 KB Output is correct
5 Correct 77 ms 24128 KB Output is correct
6 Correct 85 ms 24012 KB Output is correct
7 Correct 77 ms 24120 KB Output is correct
8 Correct 93 ms 24112 KB Output is correct
9 Correct 93 ms 24020 KB Output is correct
10 Correct 85 ms 24208 KB Output is correct
11 Correct 105 ms 24448 KB Output is correct
12 Correct 98 ms 24384 KB Output is correct
13 Correct 113 ms 24396 KB Output is correct
14 Correct 106 ms 24220 KB Output is correct
15 Correct 91 ms 24084 KB Output is correct
16 Correct 84 ms 24004 KB Output is correct
17 Correct 105 ms 24396 KB Output is correct
18 Correct 105 ms 24392 KB Output is correct
19 Correct 82 ms 24120 KB Output is correct
20 Correct 86 ms 24668 KB Output is correct
21 Correct 78 ms 25284 KB Output is correct
22 Correct 81 ms 24672 KB Output is correct
23 Correct 76 ms 24532 KB Output is correct
24 Correct 83 ms 24832 KB Output is correct
25 Correct 106 ms 24824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 11596 KB Output is correct
2 Correct 13 ms 11644 KB Output is correct
3 Correct 115 ms 25064 KB Output is correct
4 Correct 114 ms 26524 KB Output is correct
5 Correct 127 ms 28232 KB Output is correct
6 Correct 148 ms 28084 KB Output is correct
7 Correct 137 ms 28304 KB Output is correct
8 Correct 132 ms 28308 KB Output is correct
9 Correct 97 ms 21968 KB Output is correct
10 Correct 87 ms 22796 KB Output is correct
11 Correct 119 ms 24244 KB Output is correct
12 Correct 109 ms 26860 KB Output is correct
13 Correct 140 ms 27476 KB Output is correct
14 Correct 129 ms 28100 KB Output is correct
15 Correct 141 ms 28040 KB Output is correct
16 Correct 104 ms 24292 KB Output is correct
17 Correct 77 ms 24052 KB Output is correct
18 Correct 74 ms 24652 KB Output is correct
19 Correct 82 ms 24384 KB Output is correct
20 Correct 78 ms 24556 KB Output is correct
21 Correct 107 ms 28000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 11572 KB Output is correct
2 Correct 13 ms 11656 KB Output is correct
3 Correct 92 ms 25328 KB Output is correct
4 Correct 118 ms 26020 KB Output is correct
5 Correct 119 ms 26364 KB Output is correct
6 Correct 119 ms 28200 KB Output is correct
7 Correct 91 ms 25104 KB Output is correct
8 Correct 86 ms 25424 KB Output is correct
9 Correct 96 ms 26376 KB Output is correct
10 Correct 122 ms 28068 KB Output is correct
11 Correct 107 ms 28100 KB Output is correct
12 Correct 109 ms 28732 KB Output is correct
13 Correct 108 ms 24268 KB Output is correct
14 Correct 96 ms 22696 KB Output is correct
15 Correct 115 ms 24248 KB Output is correct
16 Correct 84 ms 22808 KB Output is correct
17 Correct 103 ms 24204 KB Output is correct
18 Correct 92 ms 22696 KB Output is correct
19 Correct 117 ms 26900 KB Output is correct
20 Correct 114 ms 27556 KB Output is correct
21 Correct 133 ms 28140 KB Output is correct
22 Correct 123 ms 28260 KB Output is correct
23 Correct 144 ms 28124 KB Output is correct
24 Correct 112 ms 28140 KB Output is correct
25 Correct 114 ms 28312 KB Output is correct
26 Correct 126 ms 28160 KB Output is correct
27 Correct 96 ms 24440 KB Output is correct
28 Correct 88 ms 24264 KB Output is correct
29 Partially correct 93 ms 25064 KB Output is partially correct
30 Correct 81 ms 24412 KB Output is correct
31 Correct 87 ms 24344 KB Output is correct
32 Correct 97 ms 24516 KB Output is correct
33 Partially correct 94 ms 25056 KB Output is partially correct
34 Partially correct 101 ms 24952 KB Output is partially correct
35 Correct 87 ms 24648 KB Output is correct
36 Partially correct 80 ms 24224 KB Output is partially correct
37 Correct 82 ms 24768 KB Output is correct
38 Partially correct 97 ms 24644 KB Output is partially correct
39 Correct 133 ms 27928 KB Output is correct
40 Correct 131 ms 27928 KB Output is correct
41 Partially correct 143 ms 28012 KB Output is partially correct
42 Correct 151 ms 28080 KB Output is correct