답안 #387042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387042 2021-04-07T20:33:49 Z rainboy 자매 도시 (APIO20_swap) C++11
37 / 100
2000 ms 12140 KB
#include "swap.h"
#include <cstring>
#include <vector>

const int N = 100000, M = 200000;

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 ii[M], jj[M], 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]; char ok[N];

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

void join(int i, int j, char special) {
	i = find(i);
	j = find(j);
	if (i == j) {
		ok[i] = 1;
		return;
	}
	if (ds[i] > ds[j])
		ds[i] = j, ok[j] |= ok[i] | special;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, ok[i] |= ok[j] | special;
	}
}

int hh[M], n, m;

void init(int n_, int m_, std::vector<int> II, std::vector<int> JJ, std::vector<int> WW) {
	int h;

	n = n_, m = m_;
	for (h = 0; h < m; h++)
		ii[h] = II[h], jj[h] = JJ[h], ww[h] = WW[h], hh[h] = h;
	sort(hh, 0, m);
}

int getMinimumFuelCapacity(int u, int v) {
	static int dd[N];
	int h;

	memset(ds, -1, n * sizeof *ds);
	memset(dd, 0, n * sizeof *dd);
	memset(ok, 0, n * sizeof *ok);
	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, dd[i] > 2 || dd[j] > 2);
		if (find(u) == find(v) && ok[find(u)])
			return w;
	}
	return -1;
}
# 결과 실행 시간 메모리 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 50 ms 3456 KB Output is correct
10 Correct 66 ms 4076 KB Output is correct
11 Correct 72 ms 4096 KB Output is correct
12 Correct 74 ms 4204 KB Output is correct
13 Correct 70 ms 4204 KB Output is correct
14 Execution timed out 2083 ms 3592 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 2096 ms 6032 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 50 ms 3456 KB Output is correct
11 Correct 66 ms 4076 KB Output is correct
12 Correct 72 ms 4096 KB Output is correct
13 Correct 74 ms 4204 KB Output is correct
14 Correct 70 ms 4204 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 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 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 8 ms 1228 KB Output is correct
35 Correct 72 ms 6140 KB Output is correct
36 Correct 74 ms 6252 KB Output is correct
37 Correct 73 ms 6124 KB Output is correct
38 Correct 72 ms 6064 KB Output is correct
39 Correct 73 ms 5996 KB Output is correct
40 Correct 64 ms 5484 KB Output is correct
41 Correct 77 ms 6380 KB Output is correct
42 Correct 72 ms 6144 KB Output is correct
43 Correct 61 ms 6124 KB Output is correct
44 Correct 76 ms 6388 KB Output is correct
45 Correct 101 ms 9324 KB Output is correct
46 Correct 72 ms 6124 KB Output is correct
47 Correct 73 ms 6124 KB Output is correct
48 Correct 76 ms 6892 KB Output is correct
49 Correct 79 ms 9324 KB Output is correct
50 Correct 63 ms 7404 KB Output is correct
51 Correct 81 ms 8044 KB Output is correct
52 Correct 110 ms 10092 KB Output is correct
53 Correct 113 ms 11292 KB Output is correct
54 Correct 129 ms 12140 KB Output is correct
55 Correct 64 ms 6124 KB Output is correct
56 Correct 122 ms 10732 KB Output is correct
# 결과 실행 시간 메모리 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 50 ms 3456 KB Output is correct
10 Correct 66 ms 4076 KB Output is correct
11 Correct 72 ms 4096 KB Output is correct
12 Correct 74 ms 4204 KB Output is correct
13 Correct 70 ms 4204 KB Output is correct
14 Execution timed out 2083 ms 3592 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 50 ms 3456 KB Output is correct
11 Correct 66 ms 4076 KB Output is correct
12 Correct 72 ms 4096 KB Output is correct
13 Correct 74 ms 4204 KB Output is correct
14 Correct 70 ms 4204 KB Output is correct
15 Execution timed out 2083 ms 3592 KB Time limit exceeded
16 Halted 0 ms 0 KB -