Submission #250954

# Submission time Handle Problem Language Result Execution time Memory
250954 2020-07-19T16:36:19 Z ryansee Highway Tolls (IOI18_highway) C++14
100 / 100
395 ms 14176 KB
#include "highway.h"

#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
vector<pi>v[MAXN];
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
	int m=U.size();
	FOR(i,0,m-1){
		v[U[i]].eb(V[i],i);
		v[V[i]].eb(U[i],i);
	}
	vector<int> W(m,0), pe(n,0), vis(n,0), dist(n,0), XY(n,0);
	ll init=ask(W);//, len=init/A;
	ll st=-1, en=m-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),0);
		FOR(i,0,mid)W[i]=1;
		if(ask(W)>init)en=mid;
		else st=mid;
	}
	ll x=U[en],y=V[en];
	queue<ll> q;
	q.emplace(x), q.emplace(y), vis[x]=vis[y]=1, dist[x]=dist[y]=0, XY[y]=1, pe[x]=pe[y]=en;
	while(q.size()){
		ll x=q.front();
		q.pop();
		for(auto i:v[x]) if(!vis[i.f]) {
			pe[i.f]=i.s, vis[i.f]=1, dist[i.f]=dist[x]+1, XY[i.f]=XY[x];
			q.emplace(i.f);
		} else assert(dist[i.f]<=dist[x]+1);
	}FOR(i,0,n-1)assert(vis[i]);
	vector<int> ppl;
	FOR(i,0,n-1)if(XY[i]==0)ppl.eb(i);
	sort(all(ppl),[&](int x,int y){return dist[x]<dist[y];});
	st=-1,en=siz(ppl)-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),1);
		FOR(i,0,mid)W[pe[ppl[i]]]=0;
		FOR(i,0,n-1)if(XY[i])W[pe[i]]=0;
		if(ask(W)==init)en=mid;
		else st=mid;
	}en=ppl[en];
	ll ans=en;
	ppl.clear();
	FOR(i,0,n-1)if(XY[i])ppl.eb(i);
	sort(all(ppl),[&](int x,int y){return dist[x]<dist[y];});
	st=-1,en=siz(ppl)-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),1);
		FOR(i,0,mid)W[pe[ppl[i]]]=0;
		FOR(i,0,n-1)if(XY[i]==0)W[pe[i]]=0;
		if(ask(W)==init)en=mid;
		else st=mid;
	}en=ppl[en];
	return answer(ans,en);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2736 KB Output is correct
4 Correct 2 ms 2736 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2560 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 14 ms 3584 KB Output is correct
3 Correct 273 ms 11220 KB Output is correct
4 Correct 153 ms 11208 KB Output is correct
5 Correct 264 ms 11240 KB Output is correct
6 Correct 155 ms 11112 KB Output is correct
7 Correct 150 ms 11160 KB Output is correct
8 Correct 130 ms 11112 KB Output is correct
9 Correct 126 ms 11112 KB Output is correct
10 Correct 144 ms 11144 KB Output is correct
11 Correct 289 ms 11076 KB Output is correct
12 Correct 207 ms 11228 KB Output is correct
13 Correct 258 ms 11148 KB Output is correct
14 Correct 159 ms 11228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3584 KB Output is correct
2 Correct 30 ms 4472 KB Output is correct
3 Correct 36 ms 5420 KB Output is correct
4 Correct 115 ms 10484 KB Output is correct
5 Correct 236 ms 10552 KB Output is correct
6 Correct 120 ms 10756 KB Output is correct
7 Correct 208 ms 10676 KB Output is correct
8 Correct 152 ms 10520 KB Output is correct
9 Correct 110 ms 10756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 20 ms 3564 KB Output is correct
3 Correct 142 ms 9448 KB Output is correct
4 Correct 129 ms 11148 KB Output is correct
5 Correct 225 ms 11184 KB Output is correct
6 Correct 231 ms 11108 KB Output is correct
7 Correct 247 ms 11284 KB Output is correct
8 Correct 131 ms 11180 KB Output is correct
9 Correct 265 ms 11112 KB Output is correct
10 Correct 150 ms 11128 KB Output is correct
11 Correct 166 ms 11224 KB Output is correct
12 Correct 278 ms 11272 KB Output is correct
13 Correct 288 ms 11244 KB Output is correct
14 Correct 293 ms 10992 KB Output is correct
15 Correct 194 ms 11184 KB Output is correct
16 Correct 142 ms 11120 KB Output is correct
17 Correct 170 ms 11236 KB Output is correct
18 Correct 213 ms 11376 KB Output is correct
19 Correct 230 ms 11184 KB Output is correct
20 Correct 162 ms 11404 KB Output is correct
21 Correct 115 ms 11252 KB Output is correct
22 Correct 123 ms 11280 KB Output is correct
23 Correct 158 ms 10684 KB Output is correct
24 Correct 184 ms 10668 KB Output is correct
25 Correct 175 ms 11176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3704 KB Output is correct
2 Correct 17 ms 3840 KB Output is correct
3 Correct 299 ms 11888 KB Output is correct
4 Correct 292 ms 12716 KB Output is correct
5 Correct 228 ms 14144 KB Output is correct
6 Correct 242 ms 13948 KB Output is correct
7 Correct 395 ms 13952 KB Output is correct
8 Correct 225 ms 13908 KB Output is correct
9 Correct 222 ms 10996 KB Output is correct
10 Correct 321 ms 12196 KB Output is correct
11 Correct 192 ms 12348 KB Output is correct
12 Correct 373 ms 13620 KB Output is correct
13 Correct 238 ms 13804 KB Output is correct
14 Correct 247 ms 14028 KB Output is correct
15 Correct 216 ms 14064 KB Output is correct
16 Correct 181 ms 13000 KB Output is correct
17 Correct 247 ms 11456 KB Output is correct
18 Correct 170 ms 11700 KB Output is correct
19 Correct 140 ms 11372 KB Output is correct
20 Correct 169 ms 11544 KB Output is correct
21 Correct 211 ms 14092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3704 KB Output is correct
2 Correct 22 ms 3832 KB Output is correct
3 Correct 296 ms 11668 KB Output is correct
4 Correct 195 ms 12008 KB Output is correct
5 Correct 193 ms 12440 KB Output is correct
6 Correct 361 ms 14116 KB Output is correct
7 Correct 281 ms 11964 KB Output is correct
8 Correct 165 ms 12196 KB Output is correct
9 Correct 196 ms 12448 KB Output is correct
10 Correct 366 ms 13904 KB Output is correct
11 Correct 239 ms 13916 KB Output is correct
12 Correct 385 ms 13928 KB Output is correct
13 Correct 138 ms 12344 KB Output is correct
14 Correct 150 ms 12212 KB Output is correct
15 Correct 297 ms 12352 KB Output is correct
16 Correct 152 ms 12224 KB Output is correct
17 Correct 289 ms 12340 KB Output is correct
18 Correct 160 ms 12224 KB Output is correct
19 Correct 232 ms 13644 KB Output is correct
20 Correct 243 ms 13944 KB Output is correct
21 Correct 394 ms 13864 KB Output is correct
22 Correct 248 ms 13916 KB Output is correct
23 Correct 233 ms 13968 KB Output is correct
24 Correct 236 ms 13860 KB Output is correct
25 Correct 311 ms 14116 KB Output is correct
26 Correct 219 ms 14168 KB Output is correct
27 Correct 251 ms 11584 KB Output is correct
28 Correct 139 ms 11340 KB Output is correct
29 Correct 136 ms 12096 KB Output is correct
30 Correct 128 ms 11532 KB Output is correct
31 Correct 125 ms 11536 KB Output is correct
32 Correct 129 ms 11360 KB Output is correct
33 Correct 211 ms 11900 KB Output is correct
34 Correct 168 ms 11620 KB Output is correct
35 Correct 137 ms 11420 KB Output is correct
36 Correct 130 ms 11300 KB Output is correct
37 Correct 126 ms 11864 KB Output is correct
38 Correct 228 ms 11556 KB Output is correct
39 Correct 379 ms 14088 KB Output is correct
40 Correct 369 ms 14176 KB Output is correct
41 Correct 322 ms 14076 KB Output is correct
42 Correct 237 ms 13912 KB Output is correct