Submission #387038

# Submission time Handle Problem Language Result Execution time Memory
387038 2021-04-07T20:16:37 Z rainboy Swapping Cities (APIO20_swap) C++11
13 / 100
153 ms 8276 KB
#include "swap.h"
#include <cstring>
#include <vector>

const int N = 100000, M = 200000, INF = 0x3f3f3f3f;

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int ww[M];

void sort(int *hh, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (ww[hh[j]] == ww[h])
				j++;
			else if (ww[hh[j]] < ww[h]) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		sort(hh, l, i);
		l = k;
	}
}

int ds[N], ww_[N], ww1[N];

int find(int i) {
	return ds[i] < 0 ? i : find(ds[i]);
}

void join(int i, int j, int w, int special) {
	i = find(i);
	j = find(j);
	if (i == j) {
		ww1[i] = min(ww1[i], w);
		return;
	}
	if (ds[i] > ds[j]) {
		ds[i] = j, ww_[i] = w;
		ww1[j] = min(ww1[j], ww1[i]);
		if (special)
			ww1[j] = min(ww1[j], w);
	} else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, ww_[j] = w;
		ww1[i] = min(ww1[i], ww1[j]);
		if (special)
			ww1[i] = min(ww1[i], w);
	}
}

int n, m;

void init(int n_, int m_, std::vector<int> ii, std::vector<int> jj, std::vector<int> WW) {
	static int hh[M], dd[N];
	int h;

	n = n_, m = m_;
	for (h = 0; h < m; h++)
		ww[h] = WW[h], hh[h] = h;
	sort(hh, 0, m);
	memset(dd, 0, n * sizeof *dd);
	memset(ds, -1, n * sizeof *ds);
	memset(ww_, 0x3f, n * sizeof *ww_);
	memset(ww1, 0x3f, n * sizeof *ww1);
	for (h = 0; h < m; h++) {
		int i = ii[hh[h]], j = jj[hh[h]], w = ww[hh[h]];

		dd[i]++, dd[j]++;
		join(i, j, w, dd[i] > 2 || dd[j] > 2);
	}
}

int getMinimumFuelCapacity(int i, int j) {
	long long w1 = 0;

	while (i != j)
		if (ww_[i] < ww_[j])
			w1 = ww_[i], i = ds[i];
		else
			w1 = ww_[j], j = ds[j];
	while (i >= 0) {
		if (ww1[i] != INF)
			return max(w1, ww1[i]);
		i = ds[i];
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 45 ms 3948 KB Output is correct
10 Correct 57 ms 4844 KB Output is correct
11 Correct 55 ms 4716 KB Output is correct
12 Correct 66 ms 4972 KB Output is correct
13 Correct 59 ms 4972 KB Output is correct
14 Correct 57 ms 4204 KB Output is correct
15 Correct 141 ms 6772 KB Output is correct
16 Correct 149 ms 6808 KB Output is correct
17 Correct 146 ms 6864 KB Output is correct
18 Correct 123 ms 6868 KB Output is correct
19 Correct 75 ms 4532 KB Output is correct
20 Correct 145 ms 7912 KB Output is correct
21 Correct 146 ms 7972 KB Output is correct
22 Correct 153 ms 8144 KB Output is correct
23 Correct 130 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 116 ms 7824 KB Output is correct
4 Correct 116 ms 7920 KB Output is correct
5 Correct 119 ms 8068 KB Output is correct
6 Correct 115 ms 7764 KB Output is correct
7 Correct 120 ms 8044 KB Output is correct
8 Correct 120 ms 7836 KB Output is correct
9 Correct 120 ms 7912 KB Output is correct
10 Correct 120 ms 7972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 45 ms 3948 KB Output is correct
11 Correct 57 ms 4844 KB Output is correct
12 Correct 55 ms 4716 KB Output is correct
13 Correct 66 ms 4972 KB Output is correct
14 Correct 59 ms 4972 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 45 ms 3948 KB Output is correct
10 Correct 57 ms 4844 KB Output is correct
11 Correct 55 ms 4716 KB Output is correct
12 Correct 66 ms 4972 KB Output is correct
13 Correct 59 ms 4972 KB Output is correct
14 Correct 57 ms 4204 KB Output is correct
15 Correct 141 ms 6772 KB Output is correct
16 Correct 149 ms 6808 KB Output is correct
17 Correct 146 ms 6864 KB Output is correct
18 Correct 123 ms 6868 KB Output is correct
19 Correct 116 ms 7824 KB Output is correct
20 Correct 116 ms 7920 KB Output is correct
21 Correct 119 ms 8068 KB Output is correct
22 Correct 115 ms 7764 KB Output is correct
23 Correct 120 ms 8044 KB Output is correct
24 Correct 120 ms 7836 KB Output is correct
25 Correct 120 ms 7912 KB Output is correct
26 Correct 120 ms 7972 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Incorrect 1 ms 364 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 45 ms 3948 KB Output is correct
11 Correct 57 ms 4844 KB Output is correct
12 Correct 55 ms 4716 KB Output is correct
13 Correct 66 ms 4972 KB Output is correct
14 Correct 59 ms 4972 KB Output is correct
15 Correct 57 ms 4204 KB Output is correct
16 Correct 141 ms 6772 KB Output is correct
17 Correct 149 ms 6808 KB Output is correct
18 Correct 146 ms 6864 KB Output is correct
19 Correct 123 ms 6868 KB Output is correct
20 Correct 116 ms 7824 KB Output is correct
21 Correct 116 ms 7920 KB Output is correct
22 Correct 119 ms 8068 KB Output is correct
23 Correct 115 ms 7764 KB Output is correct
24 Correct 120 ms 8044 KB Output is correct
25 Correct 120 ms 7836 KB Output is correct
26 Correct 120 ms 7912 KB Output is correct
27 Correct 120 ms 7972 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Incorrect 1 ms 364 KB Output isn't correct
34 Halted 0 ms 0 KB -