Submission #158269

# Submission time Handle Problem Language Result Execution time Memory
158269 2019-10-16T01:46:35 Z kig9981 Highway Tolls (IOI18_highway) C++17
46 / 100
322 ms 15580 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);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3112 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Runtime error 10 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 3192 KB Output is correct
2 Correct 43 ms 3664 KB Output is correct
3 Correct 206 ms 8100 KB Output is correct
4 Correct 205 ms 8044 KB Output is correct
5 Correct 230 ms 8040 KB Output is correct
6 Correct 210 ms 7960 KB Output is correct
7 Correct 210 ms 8044 KB Output is correct
8 Correct 196 ms 7892 KB Output is correct
9 Correct 192 ms 8056 KB Output is correct
10 Correct 195 ms 8144 KB Output is correct
11 Correct 208 ms 7860 KB Output is correct
12 Correct 201 ms 7824 KB Output is correct
13 Correct 208 ms 7796 KB Output is correct
14 Correct 194 ms 7908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3576 KB Output is correct
2 Correct 41 ms 4088 KB Output is correct
3 Correct 52 ms 4664 KB Output is correct
4 Correct 167 ms 7716 KB Output is correct
5 Correct 162 ms 7800 KB Output is correct
6 Correct 176 ms 7732 KB Output is correct
7 Correct 149 ms 7808 KB Output is correct
8 Correct 175 ms 7796 KB Output is correct
9 Correct 163 ms 7756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3192 KB Output is correct
2 Correct 25 ms 3576 KB Output is correct
3 Correct 138 ms 6820 KB Output is correct
4 Correct 222 ms 8008 KB Output is correct
5 Correct 200 ms 7932 KB Output is correct
6 Correct 235 ms 7956 KB Output is correct
7 Correct 190 ms 7900 KB Output is correct
8 Correct 174 ms 7864 KB Output is correct
9 Correct 214 ms 8108 KB Output is correct
10 Correct 210 ms 8128 KB Output is correct
11 Correct 223 ms 7796 KB Output is correct
12 Correct 217 ms 7800 KB Output is correct
13 Correct 223 ms 7820 KB Output is correct
14 Correct 215 ms 7796 KB Output is correct
15 Correct 195 ms 7900 KB Output is correct
16 Correct 196 ms 7944 KB Output is correct
17 Correct 207 ms 7776 KB Output is correct
18 Correct 252 ms 7736 KB Output is correct
19 Correct 195 ms 7888 KB Output is correct
20 Correct 222 ms 7780 KB Output is correct
21 Correct 187 ms 9148 KB Output is correct
22 Correct 216 ms 9176 KB Output is correct
23 Correct 230 ms 8980 KB Output is correct
24 Correct 232 ms 8868 KB Output is correct
25 Correct 219 ms 8032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3704 KB Output is correct
2 Correct 32 ms 3704 KB Output is correct
3 Correct 224 ms 8352 KB Output is correct
4 Correct 232 ms 8628 KB Output is correct
5 Correct 292 ms 9008 KB Output is correct
6 Correct 282 ms 9032 KB Output is correct
7 Correct 280 ms 9024 KB Output is correct
8 Correct 301 ms 9112 KB Output is correct
9 Runtime error 227 ms 14888 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 27 ms 3624 KB Output is correct
2 Correct 28 ms 3704 KB Output is correct
3 Correct 211 ms 8284 KB Output is correct
4 Correct 238 ms 8356 KB Output is correct
5 Correct 251 ms 8532 KB Output is correct
6 Correct 322 ms 9120 KB Output is correct
7 Correct 256 ms 8308 KB Output is correct
8 Correct 233 ms 8368 KB Output is correct
9 Correct 226 ms 8464 KB Output is correct
10 Correct 267 ms 8964 KB Output is correct
11 Correct 278 ms 9012 KB Output is correct
12 Correct 271 ms 9148 KB Output is correct
13 Runtime error 262 ms 15580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -