Submission #120249

# Submission time Handle Problem Language Result Execution time Memory
120249 2019-06-24T05:20:51 Z 윤교준(#2950) Highway Tolls (IOI18_highway) C++14
36 / 100
358 ms 36832 KB
#include "highway.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 90055;
const int MAXM = 130055;

vector<int> G[MAXN];
int A[MAXM], B[MAXM];

vector<int> TL[MAXN], TR[MAXN];
int TLN, TRN;
int DL[MAXN], DR[MAXN];

int N, M, CA, CB;
int L, EI, TLI, TRI;
int Sidx, Eidx;

map<vector<int>, ll> QMP;
inline ll getAns(vector<int> V) {
	vector<int> T(M, 0);
	for(int v : V) T[v] = 1;
	auto it = QMP.find(T);
	if(QMP.end() != it)
		return it->second;
	ll ret = ask(T);
	QMP[T] = ret;
	return ret;
}

void getOneEdge() {
	int s = 0, e = M-1; for(int m; s < e;) {
		m = (s+e) >> 1;
		vector<int> V;
		for(int i = 0; i <= m; i++) V.eb(i);
		ll t = getAns(V);
		if(t == ll(CA) * L) s = m+1;
		else e = m;
	}
	EI = s;
}

void doBFS(int d[], int sv) {
	fill(d, d+N, INF);
	d[sv] = 0;
	queue<int> PQ; PQ.push(sv);
	for(int idx, dst; !PQ.empty(); PQ.pop()) {
		idx = PQ.front(); dst = d[idx] + 1;
		for(int e : G[idx]) {
			int v = A[e] ^ B[e] ^ idx;
			if(d[v] <= dst) continue;
			d[v] = dst;
			PQ.push(v);
		}
	}
}

void getTL() {
	int s = 0, e = TLN; for(int m; s < e;) {
		m = (s+e+1) >> 1;
		vector<int> V;
		for(int i = m; i <= TLN; i++) {
			for(int v : TL[i]) {
				for(int e : G[v])
					V.eb(e);
			}
		}
		ll t = getAns(V);
		if(t == ll(CA) * L) e = m-1;
		else s = m;
	}
	TLI = s;
}

int getIdx(vector<int> V) {
	int n = sz(V), s = 0, e = n-1; for(int m; s < e;) {
		m = (s+e) >> 1;
		vector<int> E;
		for(int i = 0; i <= m; i++) {
			int v = V[i];
			for(int e : G[v])
				E.eb(e);
		}
		ll t = getAns(E);
		if(t == ll(CA) * L) s = m+1;
		else e = m;
	}
	return V[s];
}

void process() {
	for(int i = 0; i < M; i++)
		if(A[i] > B[i]) swap(A[i], B[i]);
	for(int i = 0; i < M; i++) {
		G[A[i]].eb(i);
		G[B[i]].eb(i);
	}
	L = getAns(vector<int>()) / CA;
	getOneEdge();
	doBFS(DL, A[EI]);
	doBFS(DR, B[EI]);

	for(int i = 0; i < N; i++) {
		if(DL[i] < DR[i]) {
			TL[DL[i]].eb(i);
			upmax(TLN, DL[i]);
		}
		if(DL[i] > DR[i]) {
			TR[DR[i]].eb(i);
			upmax(TRN, DR[i]);
		}
	}

	getTL();
	TRI = L - TLI - 1;

	Sidx = getIdx(TL[TLI]);
	Eidx = getIdx(TR[TRI]);

	answer(Sidx, Eidx);
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	::N = N;
	::M = sz(U);
	::CA = A;
	::CB = B;
	for(int i = 0; i < M; i++) {
		::A[i] = U[i];
		::B[i] = V[i];
	}
	process();
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6760 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6764 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 8 ms 6568 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 8 ms 6648 KB Output is correct
9 Correct 8 ms 6648 KB Output is correct
10 Correct 8 ms 6680 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 7 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Correct 31 ms 8612 KB Output is correct
3 Correct 216 ms 27612 KB Output is correct
4 Correct 224 ms 29292 KB Output is correct
5 Correct 230 ms 29080 KB Output is correct
6 Correct 242 ms 24160 KB Output is correct
7 Correct 242 ms 29368 KB Output is correct
8 Correct 224 ms 27372 KB Output is correct
9 Correct 240 ms 26604 KB Output is correct
10 Correct 236 ms 26224 KB Output is correct
11 Correct 276 ms 25448 KB Output is correct
12 Correct 237 ms 26812 KB Output is correct
13 Correct 241 ms 25320 KB Output is correct
14 Correct 298 ms 26180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8416 KB Output is correct
2 Correct 43 ms 10624 KB Output is correct
3 Correct 91 ms 14088 KB Output is correct
4 Correct 197 ms 30028 KB Output is correct
5 Correct 204 ms 28136 KB Output is correct
6 Correct 174 ms 26980 KB Output is correct
7 Correct 228 ms 28552 KB Output is correct
8 Correct 223 ms 27384 KB Output is correct
9 Correct 235 ms 29300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6756 KB Output is correct
2 Correct 31 ms 8752 KB Output is correct
3 Correct 158 ms 19916 KB Output is correct
4 Correct 219 ms 25532 KB Output is correct
5 Correct 229 ms 23744 KB Output is correct
6 Correct 233 ms 24172 KB Output is correct
7 Correct 231 ms 23272 KB Output is correct
8 Correct 249 ms 24120 KB Output is correct
9 Correct 251 ms 29076 KB Output is correct
10 Correct 234 ms 28676 KB Output is correct
11 Correct 229 ms 24872 KB Output is correct
12 Correct 233 ms 25164 KB Output is correct
13 Correct 314 ms 26532 KB Output is correct
14 Correct 280 ms 26896 KB Output is correct
15 Correct 208 ms 22000 KB Output is correct
16 Correct 194 ms 19960 KB Output is correct
17 Correct 248 ms 26140 KB Output is correct
18 Correct 291 ms 27372 KB Output is correct
19 Correct 197 ms 23688 KB Output is correct
20 Correct 254 ms 25596 KB Output is correct
21 Correct 234 ms 26872 KB Output is correct
22 Correct 247 ms 27220 KB Output is correct
23 Correct 244 ms 34216 KB Output is correct
24 Incorrect 303 ms 36248 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 8720 KB Output is correct
2 Correct 32 ms 8928 KB Output is correct
3 Correct 237 ms 28396 KB Output is correct
4 Correct 225 ms 30228 KB Output is correct
5 Correct 303 ms 36316 KB Output is correct
6 Correct 340 ms 36832 KB Output is correct
7 Correct 313 ms 34460 KB Output is correct
8 Correct 304 ms 31852 KB Output is correct
9 Correct 267 ms 23516 KB Output is correct
10 Correct 274 ms 24212 KB Output is correct
11 Correct 307 ms 32304 KB Output is correct
12 Correct 269 ms 32344 KB Output is correct
13 Correct 327 ms 34036 KB Output is correct
14 Correct 273 ms 33208 KB Output is correct
15 Correct 305 ms 33628 KB Output is correct
16 Correct 305 ms 31152 KB Output is correct
17 Correct 235 ms 31792 KB Output is correct
18 Correct 220 ms 31636 KB Output is correct
19 Correct 274 ms 31916 KB Output is correct
20 Correct 262 ms 32736 KB Output is correct
21 Correct 358 ms 35184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8952 KB Output is correct
2 Correct 26 ms 8856 KB Output is correct
3 Correct 242 ms 30072 KB Output is correct
4 Correct 270 ms 29344 KB Output is correct
5 Correct 292 ms 31676 KB Output is correct
6 Correct 341 ms 32816 KB Output is correct
7 Correct 278 ms 29272 KB Output is correct
8 Correct 248 ms 29716 KB Output is correct
9 Correct 259 ms 30228 KB Output is correct
10 Correct 328 ms 34020 KB Output is correct
11 Correct 351 ms 33364 KB Output is correct
12 Correct 319 ms 33840 KB Output is correct
13 Correct 276 ms 26752 KB Output is correct
14 Correct 287 ms 24124 KB Output is correct
15 Correct 248 ms 23436 KB Output is correct
16 Correct 274 ms 24204 KB Output is correct
17 Correct 305 ms 31768 KB Output is correct
18 Correct 283 ms 30676 KB Output is correct
19 Correct 308 ms 32756 KB Output is correct
20 Correct 310 ms 31988 KB Output is correct
21 Correct 340 ms 35260 KB Output is correct
22 Correct 287 ms 33744 KB Output is correct
23 Correct 324 ms 36188 KB Output is correct
24 Correct 337 ms 33676 KB Output is correct
25 Correct 337 ms 32664 KB Output is correct
26 Correct 314 ms 33252 KB Output is correct
27 Partially correct 263 ms 33292 KB Output is partially correct
28 Correct 228 ms 31608 KB Output is correct
29 Correct 253 ms 29248 KB Output is correct
30 Correct 255 ms 26876 KB Output is correct
31 Partially correct 210 ms 32268 KB Output is partially correct
32 Correct 262 ms 31520 KB Output is correct
33 Correct 223 ms 31600 KB Output is correct
34 Partially correct 264 ms 32748 KB Output is partially correct
35 Correct 232 ms 31508 KB Output is correct
36 Incorrect 268 ms 32996 KB Output isn't correct
37 Halted 0 ms 0 KB -