Submission #120352

# Submission time Handle Problem Language Result Execution time Memory
120352 2019-06-24T08:46:47 Z 김세빈(#2948) Highway Tolls (IOI18_highway) C++14
51 / 100
415 ms 11196 KB
#include <bits/stdc++.h>

#include "highway.h"

using namespace std;

typedef long long ll;

vector <int> G[101010];
queue <int> Q;
int N[101010], D[101010], P[101010];
int cnt;

void dfs(int p)
{
	N[p] = ++cnt;
	
	for(int &t: G[p]){
		if(!N[t]) dfs(t);
	}
}

void bfs(int n, int p)
{
	int i;
	
	for(i=0; i<n; i++){
		N[i] = 0;
	}
	
	cnt = 0; Q.push(p);
	N[p] = ++cnt; D[p] = 0;
	
	for(; !Q.empty(); ){
		p = Q.front(); Q.pop();
		for(int &t: G[p]){
			if(!N[t]){
				P[t] = p; D[t] = D[p] + 1;
				N[t] = ++cnt;
				Q.push(t);
			}
		}
	}
}
void find_pair(int n, vector <int> U, vector <int> V, int a, int b)
{
	int m = U.size();
	vector <int> W(m, 0);
	int i, k, p, u, v, s, e;
	
	for(i=0; i<m; i++){
		G[U[i]].push_back(V[i]);
		G[V[i]].push_back(U[i]);
	}
	
	k = ask(W) / a;
	
	cnt = 0; dfs(0);
	
	for(s=1, e=n; s<=e; ){
		for(i=0; i<m; i++){
			if(min(N[U[i]], N[V[i]]) <= (s + e >> 1)) W[i] = 1;
			else W[i] = 0;
		}
		if(ask(W) != (ll)a * k) e = (s + e >> 1) - 1;
		else s = (s + e >> 1) + 1;
	}
	
	for(p=0; p<n; p++){
		if(N[p] == e + 1) break;
	}
	
	bfs(n, p);
	
	for(s=1, e=n; s<=e; ){
		for(i=0; i<m; i++){
			if(P[U[i]] != V[i] && P[V[i]] != U[i]) W[i] = 1;
			else if(max(N[U[i]], N[V[i]]) >= (s + e >> 1)) W[i] = 1;
			else W[i] = 0;
		}
		if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
		else e = (s + e >> 1) - 1;
	}
	
	for(u=0; u<n; u++){
		if(N[u] == s - 1) break;
	}
	
	bfs(n, u);
	
	for(i=0, cnt=0; i<n; i++){
		if(D[i] == k) N[i] = ++cnt;
		else N[i] = 0;
	}
	
	for(s=1, e=cnt; s<=e; ){
		for(i=0; i<m; i++){
			if(P[U[i]] != V[i] && P[V[i]] != U[i]) W[i] = 1;
			else if(max(N[U[i]], N[V[i]]) >= (s + e >> 1)) W[i] = 1;
			else W[i] = 0;
		}
		if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
		else e = (s + e >> 1) - 1;
	}
	
	for(v=0; v<n; v++){
		if(N[v] == s - 1) break;
	}
	
	ask(W);
	
	answer(u, v);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:62:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    if(min(N[U[i]], N[V[i]]) <= (s + e >> 1)) W[i] = 1;
                                 ~~^~~
highway.cpp:65:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(ask(W) != (ll)a * k) e = (s + e >> 1) - 1;
                                ~~^~~
highway.cpp:66:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else s = (s + e >> 1) + 1;
             ~~^~~
highway.cpp:78:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    else if(max(N[U[i]], N[V[i]]) >= (s + e >> 1)) W[i] = 1;
                                      ~~^~~
highway.cpp:81:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
                                ~~^~~
highway.cpp:82:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else e = (s + e >> 1) - 1;
             ~~^~~
highway.cpp:99:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    else if(max(N[U[i]], N[V[i]]) >= (s + e >> 1)) W[i] = 1;
                                      ~~^~~
highway.cpp:102:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
                                ~~^~~
highway.cpp:103:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else e = (s + e >> 1) - 1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2600 KB Output is correct
2 Correct 4 ms 2692 KB Output is correct
3 Correct 4 ms 2600 KB Output is correct
4 Correct 4 ms 2700 KB Output is correct
5 Correct 4 ms 2776 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 3 ms 2680 KB Output is correct
8 Correct 4 ms 2780 KB Output is correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 28 ms 3240 KB Output is correct
3 Correct 238 ms 8508 KB Output is correct
4 Correct 222 ms 8516 KB Output is correct
5 Correct 247 ms 8508 KB Output is correct
6 Correct 254 ms 8500 KB Output is correct
7 Correct 267 ms 8504 KB Output is correct
8 Correct 243 ms 8580 KB Output is correct
9 Correct 237 ms 8616 KB Output is correct
10 Correct 269 ms 8508 KB Output is correct
11 Correct 273 ms 9064 KB Output is correct
12 Correct 211 ms 9316 KB Output is correct
13 Correct 256 ms 9104 KB Output is correct
14 Correct 266 ms 8816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3596 KB Output is correct
2 Correct 37 ms 4540 KB Output is correct
3 Correct 41 ms 5516 KB Output is correct
4 Correct 173 ms 11156 KB Output is correct
5 Correct 173 ms 11184 KB Output is correct
6 Correct 169 ms 11168 KB Output is correct
7 Correct 173 ms 11160 KB Output is correct
8 Correct 153 ms 11160 KB Output is correct
9 Correct 157 ms 11184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2728 KB Output is correct
2 Correct 25 ms 3320 KB Output is correct
3 Correct 170 ms 7248 KB Output is correct
4 Correct 254 ms 8592 KB Output is correct
5 Correct 233 ms 8584 KB Output is correct
6 Correct 281 ms 8500 KB Output is correct
7 Correct 247 ms 8564 KB Output is correct
8 Correct 250 ms 8536 KB Output is correct
9 Correct 311 ms 8496 KB Output is correct
10 Correct 255 ms 8508 KB Output is correct
11 Correct 241 ms 8764 KB Output is correct
12 Correct 277 ms 9388 KB Output is correct
13 Correct 291 ms 9240 KB Output is correct
14 Correct 293 ms 9360 KB Output is correct
15 Correct 267 ms 8500 KB Output is correct
16 Correct 223 ms 8572 KB Output is correct
17 Correct 244 ms 9208 KB Output is correct
18 Correct 260 ms 9024 KB Output is correct
19 Correct 231 ms 8504 KB Output is correct
20 Correct 276 ms 9584 KB Output is correct
21 Correct 245 ms 9092 KB Output is correct
22 Correct 227 ms 9188 KB Output is correct
23 Correct 284 ms 8920 KB Output is correct
24 Correct 227 ms 9172 KB Output is correct
25 Correct 276 ms 10780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3328 KB Output is correct
2 Correct 35 ms 3384 KB Output is correct
3 Correct 298 ms 9400 KB Output is correct
4 Correct 375 ms 9948 KB Output is correct
5 Correct 375 ms 10732 KB Output is correct
6 Correct 401 ms 10752 KB Output is correct
7 Correct 399 ms 10844 KB Output is correct
8 Correct 320 ms 10824 KB Output is correct
9 Correct 246 ms 7372 KB Output is correct
10 Correct 304 ms 7772 KB Output is correct
11 Correct 299 ms 7848 KB Output is correct
12 Correct 341 ms 10312 KB Output is correct
13 Correct 415 ms 10512 KB Output is correct
14 Correct 388 ms 11104 KB Output is correct
15 Correct 410 ms 11112 KB Output is correct
16 Correct 307 ms 9144 KB Output is correct
17 Incorrect 228 ms 9124 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3332 KB Output is correct
2 Correct 38 ms 3368 KB Output is correct
3 Correct 325 ms 9480 KB Output is correct
4 Correct 308 ms 9612 KB Output is correct
5 Correct 344 ms 9872 KB Output is correct
6 Correct 402 ms 10744 KB Output is correct
7 Correct 298 ms 9384 KB Output is correct
8 Correct 328 ms 9616 KB Output is correct
9 Correct 320 ms 9956 KB Output is correct
10 Correct 397 ms 10832 KB Output is correct
11 Correct 380 ms 10764 KB Output is correct
12 Correct 386 ms 10820 KB Output is correct
13 Correct 300 ms 7860 KB Output is correct
14 Correct 242 ms 7784 KB Output is correct
15 Correct 280 ms 7840 KB Output is correct
16 Correct 272 ms 7780 KB Output is correct
17 Correct 304 ms 7916 KB Output is correct
18 Correct 284 ms 7680 KB Output is correct
19 Correct 375 ms 10492 KB Output is correct
20 Correct 362 ms 10748 KB Output is correct
21 Correct 399 ms 11092 KB Output is correct
22 Correct 390 ms 11088 KB Output is correct
23 Correct 383 ms 11112 KB Output is correct
24 Correct 402 ms 11196 KB Output is correct
25 Correct 368 ms 11152 KB Output is correct
26 Correct 376 ms 11116 KB Output is correct
27 Partially correct 265 ms 9316 KB Output is partially correct
28 Partially correct 256 ms 9184 KB Output is partially correct
29 Partially correct 264 ms 9388 KB Output is partially correct
30 Correct 256 ms 9212 KB Output is correct
31 Partially correct 270 ms 9280 KB Output is partially correct
32 Partially correct 224 ms 9128 KB Output is partially correct
33 Correct 251 ms 9416 KB Output is correct
34 Partially correct 236 ms 9220 KB Output is partially correct
35 Partially correct 260 ms 9192 KB Output is partially correct
36 Partially correct 274 ms 9096 KB Output is partially correct
37 Incorrect 283 ms 9292 KB Output isn't correct
38 Halted 0 ms 0 KB -