답안 #988945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988945 2024-05-27T04:28:01 Z flappybird 자매 도시 (APIO20_swap) C++17
100 / 100
550 ms 45252 KB
#include "swap.h"
#include <bits/stdc++.h>
#define MAX 201010
using namespace std;
typedef pair<int, int> pii;
pii edges[MAX];
int W[MAX];

vector<pii> p[MAX];
vector<pii> numv[MAX];
vector<pii> nume[MAX];
int deg[MAX];
int val[MAX];
int rnk[MAX];

int N, M;

int getp(int v, int t) {
	int loc = lower_bound(p[v].begin(), p[v].end(), pii(t + 1, -2)) - p[v].begin();
	loc--;
	return p[v][loc].second;
}

int find(int v, int t) {
	int p = getp(v, t);
	if (v == p) return p;
	else return find(p, t);
}

int getnumv(int v, int t) {
	int loc = lower_bound(numv[v].begin(), numv[v].end(), pii(t + 1, -2)) - numv[v].begin();
	loc--;
	return numv[v][loc].second;
}

int getnume(int v, int t) {
	int loc = lower_bound(nume[v].begin(), nume[v].end(), pii(t + 1, -2)) - nume[v].begin();
	loc--;
	return nume[v][loc].second;
}

void uni(int u, int v, int t) {
	deg[u]++;
	deg[v]++;
	int mx = max(deg[u], deg[v]);
	u = find(u, t);
	v = find(v, t);
	if (rnk[u] < rnk[v]) swap(u, v);
	if (u == v) nume[v].emplace_back(t, nume[v].back().second + 1);
	else {
		if (rnk[u] == rnk[v]) rnk[u]++;
		p[v].emplace_back(t, u);
		numv[u].emplace_back(t, numv[v].back().second + numv[u].back().second);
		nume[u].emplace_back(t, nume[v].back().second + nume[u].back().second + 1);
		if (val[v] <= t) val[u] = min(val[u], t);
	}
	if (mx > 2) val[u] = min(val[u], t);
}

void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> _W) {
	N = _N;
	M = _M;
	int i;
	vector<int> v;
	for (i = 0; i < M; i++) v.push_back(i);
	sort(v.begin(), v.end(), [&](int i, int j) {return _W[i] < _W[j]; });
	i = 0;
	for (auto x : v) {
		edges[i] = pii(U[x], V[x]);
		W[i] = _W[x];
		i++;
	}
	for (i = 0; i < N; i++) p[i].emplace_back(-1, i), nume[i].emplace_back(-1, 0), numv[i].emplace_back(-1, 1), val[i] = M;
	for (i = 0; i < M; i++) {
		uni(edges[i].first, edges[i].second, i);
	}
}

int getMinimumFuelCapacity(int X, int Y) {
	int l, r;
	l = -1, r = M;
	while (r - l > 1) {
		int m = (l + r + 2) >> 1;
		m--;
		int x = find(X, m);
		int y = find(Y, m);
		if (x != y) {
			l = m;
			continue;
		}
		if (getnumv(x, m) <= getnume(x, m)) r = m;
		else if (val[x] <= m) r = m;
		else l = m;
	}
	if (r == M) return -1;
	return W[r];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14700 KB Output is correct
5 Correct 6 ms 14684 KB Output is correct
6 Correct 7 ms 14684 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 8 ms 14552 KB Output is correct
9 Correct 73 ms 28200 KB Output is correct
10 Correct 98 ms 31432 KB Output is correct
11 Correct 94 ms 31180 KB Output is correct
12 Correct 72 ms 32032 KB Output is correct
13 Correct 55 ms 30664 KB Output is correct
14 Correct 85 ms 28304 KB Output is correct
15 Correct 369 ms 32984 KB Output is correct
16 Correct 413 ms 32460 KB Output is correct
17 Correct 413 ms 33568 KB Output is correct
18 Correct 263 ms 32544 KB Output is correct
19 Correct 192 ms 20816 KB Output is correct
20 Correct 356 ms 38348 KB Output is correct
21 Correct 388 ms 37924 KB Output is correct
22 Correct 426 ms 39332 KB Output is correct
23 Correct 294 ms 37500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 337 ms 32248 KB Output is correct
4 Correct 357 ms 32760 KB Output is correct
5 Correct 400 ms 32484 KB Output is correct
6 Correct 394 ms 32512 KB Output is correct
7 Correct 357 ms 32584 KB Output is correct
8 Correct 355 ms 31988 KB Output is correct
9 Correct 355 ms 32712 KB Output is correct
10 Correct 372 ms 31928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14700 KB Output is correct
5 Correct 6 ms 14684 KB Output is correct
6 Correct 7 ms 14684 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 8 ms 14552 KB Output is correct
9 Correct 5 ms 14428 KB Output is correct
10 Correct 5 ms 14660 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 5 ms 14684 KB Output is correct
13 Correct 6 ms 14572 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 5 ms 14684 KB Output is correct
17 Correct 5 ms 14936 KB Output is correct
18 Correct 6 ms 14684 KB Output is correct
19 Correct 5 ms 14684 KB Output is correct
20 Correct 6 ms 14684 KB Output is correct
21 Correct 7 ms 14684 KB Output is correct
22 Correct 6 ms 14620 KB Output is correct
23 Correct 5 ms 14684 KB Output is correct
24 Correct 6 ms 14684 KB Output is correct
25 Correct 6 ms 14680 KB Output is correct
26 Correct 6 ms 14684 KB Output is correct
27 Correct 6 ms 14684 KB Output is correct
28 Correct 6 ms 14776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 5 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 6 ms 14700 KB Output is correct
6 Correct 6 ms 14684 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 8 ms 14552 KB Output is correct
10 Correct 73 ms 28200 KB Output is correct
11 Correct 98 ms 31432 KB Output is correct
12 Correct 94 ms 31180 KB Output is correct
13 Correct 72 ms 32032 KB Output is correct
14 Correct 55 ms 30664 KB Output is correct
15 Correct 5 ms 14660 KB Output is correct
16 Correct 6 ms 14684 KB Output is correct
17 Correct 5 ms 14684 KB Output is correct
18 Correct 6 ms 14572 KB Output is correct
19 Correct 6 ms 14684 KB Output is correct
20 Correct 6 ms 14684 KB Output is correct
21 Correct 5 ms 14684 KB Output is correct
22 Correct 5 ms 14936 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 5 ms 14684 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 7 ms 14684 KB Output is correct
27 Correct 6 ms 14620 KB Output is correct
28 Correct 5 ms 14684 KB Output is correct
29 Correct 6 ms 14684 KB Output is correct
30 Correct 6 ms 14680 KB Output is correct
31 Correct 6 ms 14684 KB Output is correct
32 Correct 6 ms 14684 KB Output is correct
33 Correct 6 ms 14776 KB Output is correct
34 Correct 20 ms 17244 KB Output is correct
35 Correct 92 ms 33844 KB Output is correct
36 Correct 70 ms 33996 KB Output is correct
37 Correct 79 ms 33992 KB Output is correct
38 Correct 65 ms 33548 KB Output is correct
39 Correct 65 ms 33484 KB Output is correct
40 Correct 62 ms 31688 KB Output is correct
41 Correct 100 ms 34248 KB Output is correct
42 Correct 78 ms 33792 KB Output is correct
43 Correct 73 ms 33088 KB Output is correct
44 Correct 78 ms 33992 KB Output is correct
45 Correct 126 ms 35268 KB Output is correct
46 Correct 71 ms 33900 KB Output is correct
47 Correct 67 ms 33600 KB Output is correct
48 Correct 70 ms 33904 KB Output is correct
49 Correct 60 ms 25912 KB Output is correct
50 Correct 55 ms 23732 KB Output is correct
51 Correct 73 ms 31688 KB Output is correct
52 Correct 122 ms 38852 KB Output is correct
53 Correct 137 ms 40388 KB Output is correct
54 Correct 136 ms 41412 KB Output is correct
55 Correct 61 ms 33300 KB Output is correct
56 Correct 103 ms 39364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Correct 6 ms 14700 KB Output is correct
5 Correct 6 ms 14684 KB Output is correct
6 Correct 7 ms 14684 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 8 ms 14552 KB Output is correct
9 Correct 73 ms 28200 KB Output is correct
10 Correct 98 ms 31432 KB Output is correct
11 Correct 94 ms 31180 KB Output is correct
12 Correct 72 ms 32032 KB Output is correct
13 Correct 55 ms 30664 KB Output is correct
14 Correct 85 ms 28304 KB Output is correct
15 Correct 369 ms 32984 KB Output is correct
16 Correct 413 ms 32460 KB Output is correct
17 Correct 413 ms 33568 KB Output is correct
18 Correct 263 ms 32544 KB Output is correct
19 Correct 337 ms 32248 KB Output is correct
20 Correct 357 ms 32760 KB Output is correct
21 Correct 400 ms 32484 KB Output is correct
22 Correct 394 ms 32512 KB Output is correct
23 Correct 357 ms 32584 KB Output is correct
24 Correct 355 ms 31988 KB Output is correct
25 Correct 355 ms 32712 KB Output is correct
26 Correct 372 ms 31928 KB Output is correct
27 Correct 5 ms 14660 KB Output is correct
28 Correct 6 ms 14684 KB Output is correct
29 Correct 5 ms 14684 KB Output is correct
30 Correct 6 ms 14572 KB Output is correct
31 Correct 6 ms 14684 KB Output is correct
32 Correct 6 ms 14684 KB Output is correct
33 Correct 5 ms 14684 KB Output is correct
34 Correct 5 ms 14936 KB Output is correct
35 Correct 6 ms 14684 KB Output is correct
36 Correct 20 ms 17244 KB Output is correct
37 Correct 92 ms 33844 KB Output is correct
38 Correct 70 ms 33996 KB Output is correct
39 Correct 79 ms 33992 KB Output is correct
40 Correct 65 ms 33548 KB Output is correct
41 Correct 65 ms 33484 KB Output is correct
42 Correct 62 ms 31688 KB Output is correct
43 Correct 100 ms 34248 KB Output is correct
44 Correct 78 ms 33792 KB Output is correct
45 Correct 73 ms 33088 KB Output is correct
46 Correct 78 ms 33992 KB Output is correct
47 Correct 33 ms 17364 KB Output is correct
48 Correct 360 ms 38408 KB Output is correct
49 Correct 412 ms 38384 KB Output is correct
50 Correct 386 ms 38308 KB Output is correct
51 Correct 382 ms 38324 KB Output is correct
52 Correct 408 ms 37092 KB Output is correct
53 Correct 344 ms 32952 KB Output is correct
54 Correct 392 ms 39168 KB Output is correct
55 Correct 382 ms 38308 KB Output is correct
56 Correct 314 ms 37472 KB Output is correct
57 Correct 372 ms 38824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 5 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 6 ms 14700 KB Output is correct
6 Correct 6 ms 14684 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 8 ms 14552 KB Output is correct
10 Correct 73 ms 28200 KB Output is correct
11 Correct 98 ms 31432 KB Output is correct
12 Correct 94 ms 31180 KB Output is correct
13 Correct 72 ms 32032 KB Output is correct
14 Correct 55 ms 30664 KB Output is correct
15 Correct 85 ms 28304 KB Output is correct
16 Correct 369 ms 32984 KB Output is correct
17 Correct 413 ms 32460 KB Output is correct
18 Correct 413 ms 33568 KB Output is correct
19 Correct 263 ms 32544 KB Output is correct
20 Correct 337 ms 32248 KB Output is correct
21 Correct 357 ms 32760 KB Output is correct
22 Correct 400 ms 32484 KB Output is correct
23 Correct 394 ms 32512 KB Output is correct
24 Correct 357 ms 32584 KB Output is correct
25 Correct 355 ms 31988 KB Output is correct
26 Correct 355 ms 32712 KB Output is correct
27 Correct 372 ms 31928 KB Output is correct
28 Correct 5 ms 14660 KB Output is correct
29 Correct 6 ms 14684 KB Output is correct
30 Correct 5 ms 14684 KB Output is correct
31 Correct 6 ms 14572 KB Output is correct
32 Correct 6 ms 14684 KB Output is correct
33 Correct 6 ms 14684 KB Output is correct
34 Correct 5 ms 14684 KB Output is correct
35 Correct 5 ms 14936 KB Output is correct
36 Correct 6 ms 14684 KB Output is correct
37 Correct 20 ms 17244 KB Output is correct
38 Correct 92 ms 33844 KB Output is correct
39 Correct 70 ms 33996 KB Output is correct
40 Correct 79 ms 33992 KB Output is correct
41 Correct 65 ms 33548 KB Output is correct
42 Correct 65 ms 33484 KB Output is correct
43 Correct 62 ms 31688 KB Output is correct
44 Correct 100 ms 34248 KB Output is correct
45 Correct 78 ms 33792 KB Output is correct
46 Correct 73 ms 33088 KB Output is correct
47 Correct 78 ms 33992 KB Output is correct
48 Correct 33 ms 17364 KB Output is correct
49 Correct 360 ms 38408 KB Output is correct
50 Correct 412 ms 38384 KB Output is correct
51 Correct 386 ms 38308 KB Output is correct
52 Correct 382 ms 38324 KB Output is correct
53 Correct 408 ms 37092 KB Output is correct
54 Correct 344 ms 32952 KB Output is correct
55 Correct 392 ms 39168 KB Output is correct
56 Correct 382 ms 38308 KB Output is correct
57 Correct 314 ms 37472 KB Output is correct
58 Correct 372 ms 38824 KB Output is correct
59 Correct 192 ms 20816 KB Output is correct
60 Correct 356 ms 38348 KB Output is correct
61 Correct 388 ms 37924 KB Output is correct
62 Correct 426 ms 39332 KB Output is correct
63 Correct 294 ms 37500 KB Output is correct
64 Correct 5 ms 14684 KB Output is correct
65 Correct 6 ms 14684 KB Output is correct
66 Correct 7 ms 14684 KB Output is correct
67 Correct 6 ms 14620 KB Output is correct
68 Correct 5 ms 14684 KB Output is correct
69 Correct 6 ms 14684 KB Output is correct
70 Correct 6 ms 14680 KB Output is correct
71 Correct 6 ms 14684 KB Output is correct
72 Correct 6 ms 14684 KB Output is correct
73 Correct 6 ms 14776 KB Output is correct
74 Correct 126 ms 35268 KB Output is correct
75 Correct 71 ms 33900 KB Output is correct
76 Correct 67 ms 33600 KB Output is correct
77 Correct 70 ms 33904 KB Output is correct
78 Correct 60 ms 25912 KB Output is correct
79 Correct 55 ms 23732 KB Output is correct
80 Correct 73 ms 31688 KB Output is correct
81 Correct 122 ms 38852 KB Output is correct
82 Correct 137 ms 40388 KB Output is correct
83 Correct 136 ms 41412 KB Output is correct
84 Correct 61 ms 33300 KB Output is correct
85 Correct 103 ms 39364 KB Output is correct
86 Correct 122 ms 22736 KB Output is correct
87 Correct 355 ms 38356 KB Output is correct
88 Correct 392 ms 38400 KB Output is correct
89 Correct 453 ms 37200 KB Output is correct
90 Correct 368 ms 29884 KB Output is correct
91 Correct 434 ms 30376 KB Output is correct
92 Correct 475 ms 35660 KB Output is correct
93 Correct 550 ms 42768 KB Output is correct
94 Correct 537 ms 44272 KB Output is correct
95 Correct 492 ms 45252 KB Output is correct
96 Correct 281 ms 37604 KB Output is correct
97 Correct 509 ms 40920 KB Output is correct