답안 #158285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158285 2019-10-16T02:35:45 Z kig9981 통행료 (IOI18_highway) C++17
51 / 100
340 ms 9532 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<M;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);
		}
	}
	for(int i=0;i<N;i++) {
		if(dist1[i]<dist2[i]) C1.push_back(i);
		else if(dist1[i]>dist2[i]) C2.push_back(i);
	}
	sort(C1.begin(),C1.end(),[&](int a, int b) {return dist1[a]<dist1[b];});
	sort(C2.begin(),C2.end(),[&](int a, int b) {return dist2[a]<dist2[b];});
	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=m;i<C1.size();i++) chk[C1[i]]=true;
		for(int i=0;i<M;i++) W[i]=chk[U[i]]^chk[V[i]];
		if(ask(W)!=D) s=m+1;
		else e=m-1;
	}
	S=C1[e];
	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=m;i<C2.size();i++) chk[C2[i]]=true;
		for(int i=0;i<M;i++) W[i]=chk[U[i]]^chk[V[i]];
		if(ask(W)!=D) s=m+1;
		else e=m-1;
	}
	T=C2[e];
	answer(S,T);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:58:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=m;i<C1.size();i++) chk[C1[i]]=true;
               ~^~~~~~~~~~
highway.cpp:68:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=m;i<C2.size();i++) chk[C2[i]]=true;
               ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3064 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Correct 4 ms 3084 KB Output is correct
4 Correct 4 ms 3160 KB Output is correct
5 Correct 5 ms 3064 KB Output is correct
6 Correct 4 ms 3064 KB Output is correct
7 Correct 4 ms 3120 KB Output is correct
8 Correct 5 ms 3192 KB Output is correct
9 Correct 4 ms 3112 KB Output is correct
10 Correct 5 ms 3112 KB Output is correct
11 Correct 4 ms 3196 KB Output is correct
12 Correct 4 ms 3112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3192 KB Output is correct
2 Correct 26 ms 3708 KB Output is correct
3 Correct 210 ms 8432 KB Output is correct
4 Correct 221 ms 8620 KB Output is correct
5 Correct 210 ms 8416 KB Output is correct
6 Correct 193 ms 8476 KB Output is correct
7 Correct 210 ms 8424 KB Output is correct
8 Correct 199 ms 8420 KB Output is correct
9 Correct 209 ms 8420 KB Output is correct
10 Correct 171 ms 8428 KB Output is correct
11 Correct 230 ms 8376 KB Output is correct
12 Correct 221 ms 8372 KB Output is correct
13 Correct 218 ms 8292 KB Output is correct
14 Correct 224 ms 8304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3832 KB Output is correct
2 Correct 56 ms 4320 KB Output is correct
3 Correct 64 ms 4944 KB Output is correct
4 Correct 180 ms 8260 KB Output is correct
5 Correct 177 ms 8256 KB Output is correct
6 Correct 177 ms 8364 KB Output is correct
7 Correct 171 ms 8344 KB Output is correct
8 Correct 181 ms 8184 KB Output is correct
9 Correct 179 ms 8308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3196 KB Output is correct
2 Correct 38 ms 3776 KB Output is correct
3 Correct 158 ms 7588 KB Output is correct
4 Correct 203 ms 8428 KB Output is correct
5 Correct 205 ms 8432 KB Output is correct
6 Correct 200 ms 8432 KB Output is correct
7 Correct 212 ms 8424 KB Output is correct
8 Correct 204 ms 8400 KB Output is correct
9 Correct 215 ms 8412 KB Output is correct
10 Correct 214 ms 8416 KB Output is correct
11 Correct 218 ms 8296 KB Output is correct
12 Correct 216 ms 8380 KB Output is correct
13 Correct 214 ms 8432 KB Output is correct
14 Correct 224 ms 8244 KB Output is correct
15 Correct 205 ms 8416 KB Output is correct
16 Correct 210 ms 8484 KB Output is correct
17 Correct 219 ms 8308 KB Output is correct
18 Correct 196 ms 8384 KB Output is correct
19 Correct 222 ms 8428 KB Output is correct
20 Correct 281 ms 8412 KB Output is correct
21 Correct 192 ms 9152 KB Output is correct
22 Correct 186 ms 9156 KB Output is correct
23 Correct 190 ms 9056 KB Output is correct
24 Correct 202 ms 8852 KB Output is correct
25 Correct 233 ms 8460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3752 KB Output is correct
2 Correct 42 ms 3800 KB Output is correct
3 Correct 233 ms 8628 KB Output is correct
4 Correct 255 ms 8984 KB Output is correct
5 Correct 292 ms 9532 KB Output is correct
6 Correct 296 ms 9472 KB Output is correct
7 Correct 340 ms 9516 KB Output is correct
8 Correct 307 ms 9404 KB Output is correct
9 Incorrect 256 ms 7616 KB Output is incorrect: {s, t} is wrong.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3704 KB Output is correct
2 Correct 29 ms 3824 KB Output is correct
3 Correct 226 ms 8672 KB Output is correct
4 Correct 220 ms 8760 KB Output is correct
5 Correct 262 ms 8868 KB Output is correct
6 Correct 292 ms 9500 KB Output is correct
7 Correct 227 ms 8724 KB Output is correct
8 Correct 243 ms 8780 KB Output is correct
9 Correct 262 ms 8908 KB Output is correct
10 Correct 293 ms 9304 KB Output is correct
11 Correct 313 ms 9480 KB Output is correct
12 Correct 296 ms 9392 KB Output is correct
13 Incorrect 247 ms 8072 KB Output is incorrect: {s, t} is wrong.
14 Halted 0 ms 0 KB -