Submission #158264

# Submission time Handle Problem Language Result Execution time Memory
158264 2019-10-16T01:27:27 Z kig9981 Highway Tolls (IOI18_highway) C++17
46 / 100
311 ms 15584 KB
#include "highway.h"
#include <bits/stdc++.h>
 
using namespace std;
 
vector<int> adj[90000];
int dist1[90000], dist2[90000];
bool chk[90000];
 
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
	int M=U.size(), S, T, s, e, E;
	vector<int> W(M,0), C1, C2;
	queue<int> Q;
	long long D=ask(W);
	for(int i=0;i<M;i++) {
		adj[U[i]].push_back(V[i]);
		adj[V[i]].push_back(U[i]);
	}
	s=0; e=N-1;
	while(s<=e) {
		int m=(s+e)>>1;
		for(int i=0;i<N;i++) W[i]=i<=m;
		if(ask(W)!=D) e=m-1;
		else s=m+1;
	}
	E=s;
	memset(dist1,0x7f,sizeof(dist1));
	memset(dist2,0x7f,sizeof(dist2));
	dist1[U[E]]=0; Q.push(U[E]);
	while(!Q.empty()) {
		int c=Q.front();
		Q.pop();
		for(auto n: adj[c]) if(dist1[n]>dist1[c]+1) {
			dist1[n]=dist1[c]+1;
			Q.push(n);
		}
	}
	dist2[V[E]]=0; Q.push(V[E]);
	while(!Q.empty()) {
		int c=Q.front();
		Q.pop();
		for(auto n: adj[c]) if(dist2[n]>dist2[c]+1) {
			dist2[n]=dist2[c]+1;
			Q.push(n);
		}
	}
	s=0; e=D/A-1;
	while(s<=e) {
		int m=(s+e)>>1;
		for(int i=0;i<M;i++) W[i]=dist1[U[i]]<dist2[U[i]] && dist1[U[i]]>=m || dist1[V[i]]<dist2[V[i]] && dist1[V[i]]>=m;
		if(ask(W)!=D) s=m+1;
		else e=m-1;
	}
	for(int i=0;i<N;i++) {
		if(dist1[i]<dist2[i] && dist1[i]==e) C1.push_back(i);
		if(dist1[i]>dist2[i] && dist2[i]==D/A-s) C2.push_back(i);
		chk[i]=false;
	}
	s=0; e=C1.size()-1;
	while(s<=e) {
		int m=(s+e)>>1;
		for(int i=0;i<N;i++) chk[i]=false;
		for(int i=0;i<=m;i++) chk[C1[i]]=true;
		for(int i=0;i<M;i++) W[i]=chk[U[i]] || chk[V[i]];
		if(ask(W)!=D) e=m-1;
		else s=m+1;
	}
	S=C1[s];
	s=0; e=C2.size()-1;
	while(s<=e) {
		int m=(s+e)>>1;
		for(int i=0;i<N;i++) chk[i]=false;
		for(int i=0;i<=m;i++) chk[C2[i]]=true;
		for(int i=0;i<M;i++) W[i]=chk[U[i]] || chk[V[i]];
		if(ask(W)!=D) e=m-1;
		else s=m+1;
	}
	T=C2[s];
	answer(S,T);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:51:53: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   for(int i=0;i<M;i++) W[i]=dist1[U[i]]<dist2[U[i]] && dist1[U[i]]>=m || dist1[V[i]]<dist2[V[i]] && dist1[V[i]]>=m;
                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3064 KB Output is correct
3 Runtime error 12 ms 6264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3092 KB Output is correct
2 Correct 38 ms 3744 KB Output is correct
3 Correct 209 ms 8048 KB Output is correct
4 Correct 212 ms 8144 KB Output is correct
5 Correct 224 ms 8032 KB Output is correct
6 Correct 211 ms 7964 KB Output is correct
7 Correct 231 ms 8056 KB Output is correct
8 Correct 201 ms 7896 KB Output is correct
9 Correct 197 ms 8040 KB Output is correct
10 Correct 201 ms 8056 KB Output is correct
11 Correct 177 ms 7848 KB Output is correct
12 Correct 198 ms 7756 KB Output is correct
13 Correct 208 ms 7908 KB Output is correct
14 Correct 186 ms 7784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3588 KB Output is correct
2 Correct 42 ms 4152 KB Output is correct
3 Correct 58 ms 4664 KB Output is correct
4 Correct 151 ms 7784 KB Output is correct
5 Correct 169 ms 7812 KB Output is correct
6 Correct 187 ms 7816 KB Output is correct
7 Correct 124 ms 7772 KB Output is correct
8 Correct 163 ms 7736 KB Output is correct
9 Correct 159 ms 7776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3192 KB Output is correct
2 Correct 26 ms 3576 KB Output is correct
3 Correct 145 ms 6844 KB Output is correct
4 Correct 211 ms 8000 KB Output is correct
5 Correct 208 ms 7928 KB Output is correct
6 Correct 208 ms 7912 KB Output is correct
7 Correct 200 ms 7888 KB Output is correct
8 Correct 208 ms 7948 KB Output is correct
9 Correct 215 ms 8156 KB Output is correct
10 Correct 201 ms 8048 KB Output is correct
11 Correct 206 ms 7804 KB Output is correct
12 Correct 207 ms 7736 KB Output is correct
13 Correct 169 ms 7768 KB Output is correct
14 Correct 216 ms 7816 KB Output is correct
15 Correct 190 ms 7936 KB Output is correct
16 Correct 185 ms 7900 KB Output is correct
17 Correct 231 ms 7824 KB Output is correct
18 Correct 224 ms 7812 KB Output is correct
19 Correct 175 ms 7896 KB Output is correct
20 Correct 202 ms 7856 KB Output is correct
21 Correct 199 ms 9240 KB Output is correct
22 Correct 206 ms 9236 KB Output is correct
23 Correct 224 ms 8976 KB Output is correct
24 Correct 228 ms 8800 KB Output is correct
25 Correct 231 ms 8068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3728 KB Output is correct
2 Correct 27 ms 3704 KB Output is correct
3 Correct 225 ms 8276 KB Output is correct
4 Correct 259 ms 8564 KB Output is correct
5 Correct 268 ms 8992 KB Output is correct
6 Correct 311 ms 9032 KB Output is correct
7 Correct 282 ms 8988 KB Output is correct
8 Correct 288 ms 8984 KB Output is correct
9 Runtime error 249 ms 14948 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3624 KB Output is correct
2 Correct 28 ms 3780 KB Output is correct
3 Correct 231 ms 8328 KB Output is correct
4 Correct 239 ms 8348 KB Output is correct
5 Correct 256 ms 8524 KB Output is correct
6 Correct 295 ms 9076 KB Output is correct
7 Correct 225 ms 8304 KB Output is correct
8 Correct 218 ms 8360 KB Output is correct
9 Correct 272 ms 8464 KB Output is correct
10 Correct 265 ms 8976 KB Output is correct
11 Correct 283 ms 9096 KB Output is correct
12 Correct 285 ms 9004 KB Output is correct
13 Runtime error 248 ms 15584 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -