Submission #988931

# Submission time Handle Problem Language Result Execution time Memory
988931 2024-05-27T03:57:00 Z flappybird Swapping Cities (APIO20_swap) C++17
0 / 100
269 ms 38344 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 rnk[MAX];

int N, M;

int find(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 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) {
	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);
	}
}

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);
	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 l = m;
	}
	if (r == M) return -1;
	return W[r];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 3 ms 16860 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 48 ms 30768 KB Output is correct
10 Correct 58 ms 33736 KB Output is correct
11 Correct 61 ms 33612 KB Output is correct
12 Correct 60 ms 34504 KB Output is correct
13 Correct 56 ms 32972 KB Output is correct
14 Correct 55 ms 30956 KB Output is correct
15 Correct 145 ms 37832 KB Output is correct
16 Correct 142 ms 37396 KB Output is correct
17 Correct 137 ms 38344 KB Output is correct
18 Correct 195 ms 37176 KB Output is correct
19 Incorrect 65 ms 23676 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Incorrect 269 ms 35784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 3 ms 16860 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16860 KB Output is correct
10 Incorrect 3 ms 16988 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16860 KB Output is correct
2 Correct 2 ms 16728 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 3 ms 16860 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 48 ms 30768 KB Output is correct
11 Correct 58 ms 33736 KB Output is correct
12 Correct 61 ms 33612 KB Output is correct
13 Correct 60 ms 34504 KB Output is correct
14 Correct 56 ms 32972 KB Output is correct
15 Incorrect 3 ms 16988 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 3 ms 16860 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 48 ms 30768 KB Output is correct
10 Correct 58 ms 33736 KB Output is correct
11 Correct 61 ms 33612 KB Output is correct
12 Correct 60 ms 34504 KB Output is correct
13 Correct 56 ms 32972 KB Output is correct
14 Correct 55 ms 30956 KB Output is correct
15 Correct 145 ms 37832 KB Output is correct
16 Correct 142 ms 37396 KB Output is correct
17 Correct 137 ms 38344 KB Output is correct
18 Correct 195 ms 37176 KB Output is correct
19 Incorrect 269 ms 35784 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16860 KB Output is correct
2 Correct 2 ms 16728 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 3 ms 16860 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 48 ms 30768 KB Output is correct
11 Correct 58 ms 33736 KB Output is correct
12 Correct 61 ms 33612 KB Output is correct
13 Correct 60 ms 34504 KB Output is correct
14 Correct 56 ms 32972 KB Output is correct
15 Correct 55 ms 30956 KB Output is correct
16 Correct 145 ms 37832 KB Output is correct
17 Correct 142 ms 37396 KB Output is correct
18 Correct 137 ms 38344 KB Output is correct
19 Correct 195 ms 37176 KB Output is correct
20 Incorrect 269 ms 35784 KB Output isn't correct
21 Halted 0 ms 0 KB -