답안 #387045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387045 2021-04-07T20:53:54 Z rainboy 자매 도시 (APIO20_swap) C++11
100 / 100
213 ms 15980 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], max(special ? 0 : ww1[i], w));
	} else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, ww_[j] = w;
		ww1[i] = min(ww1[i], max(special ? 0 : ww1[j], 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]);
		w1 = ww_[i];
		i = ds[i];
	}
	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 2 ms 364 KB Output is correct
5 Correct 2 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 52 ms 4076 KB Output is correct
10 Correct 53 ms 4844 KB Output is correct
11 Correct 54 ms 4716 KB Output is correct
12 Correct 56 ms 4972 KB Output is correct
13 Correct 56 ms 4972 KB Output is correct
14 Correct 53 ms 4204 KB Output is correct
15 Correct 142 ms 6644 KB Output is correct
16 Correct 140 ms 6684 KB Output is correct
17 Correct 144 ms 6864 KB Output is correct
18 Correct 135 ms 6864 KB Output is correct
19 Correct 76 ms 4532 KB Output is correct
20 Correct 139 ms 7784 KB Output is correct
21 Correct 146 ms 8100 KB Output is correct
22 Correct 163 ms 8272 KB Output is correct
23 Correct 128 ms 8144 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 115 ms 7820 KB Output is correct
4 Correct 134 ms 7892 KB Output is correct
5 Correct 119 ms 8192 KB Output is correct
6 Correct 118 ms 7760 KB Output is correct
7 Correct 119 ms 8044 KB Output is correct
8 Correct 119 ms 7832 KB Output is correct
9 Correct 119 ms 7916 KB Output is correct
10 Correct 117 ms 8124 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 2 ms 364 KB Output is correct
5 Correct 2 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 2 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 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 2 ms 384 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 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 1 ms 364 KB Output is correct
28 Correct 2 ms 364 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 2 ms 364 KB Output is correct
6 Correct 2 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 52 ms 4076 KB Output is correct
11 Correct 53 ms 4844 KB Output is correct
12 Correct 54 ms 4716 KB Output is correct
13 Correct 56 ms 4972 KB Output is correct
14 Correct 56 ms 4972 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 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 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 10 ms 1004 KB Output is correct
35 Correct 56 ms 4972 KB Output is correct
36 Correct 53 ms 4972 KB Output is correct
37 Correct 54 ms 5100 KB Output is correct
38 Correct 54 ms 4992 KB Output is correct
39 Correct 53 ms 4984 KB Output is correct
40 Correct 49 ms 4588 KB Output is correct
41 Correct 56 ms 4972 KB Output is correct
42 Correct 54 ms 4972 KB Output is correct
43 Correct 54 ms 4972 KB Output is correct
44 Correct 58 ms 5172 KB Output is correct
45 Correct 84 ms 6124 KB Output is correct
46 Correct 54 ms 4972 KB Output is correct
47 Correct 58 ms 4972 KB Output is correct
48 Correct 61 ms 5356 KB Output is correct
49 Correct 84 ms 5356 KB Output is correct
50 Correct 72 ms 4332 KB Output is correct
51 Correct 74 ms 5356 KB Output is correct
52 Correct 95 ms 6892 KB Output is correct
53 Correct 104 ms 7532 KB Output is correct
54 Correct 117 ms 8172 KB Output is correct
55 Correct 55 ms 4972 KB Output is correct
56 Correct 105 ms 7276 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 2 ms 364 KB Output is correct
5 Correct 2 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 52 ms 4076 KB Output is correct
10 Correct 53 ms 4844 KB Output is correct
11 Correct 54 ms 4716 KB Output is correct
12 Correct 56 ms 4972 KB Output is correct
13 Correct 56 ms 4972 KB Output is correct
14 Correct 53 ms 4204 KB Output is correct
15 Correct 142 ms 6644 KB Output is correct
16 Correct 140 ms 6684 KB Output is correct
17 Correct 144 ms 6864 KB Output is correct
18 Correct 135 ms 6864 KB Output is correct
19 Correct 115 ms 7820 KB Output is correct
20 Correct 134 ms 7892 KB Output is correct
21 Correct 119 ms 8192 KB Output is correct
22 Correct 118 ms 7760 KB Output is correct
23 Correct 119 ms 8044 KB Output is correct
24 Correct 119 ms 7832 KB Output is correct
25 Correct 119 ms 7916 KB Output is correct
26 Correct 117 ms 8124 KB Output is correct
27 Correct 1 ms 364 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 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 10 ms 1004 KB Output is correct
37 Correct 56 ms 4972 KB Output is correct
38 Correct 53 ms 4972 KB Output is correct
39 Correct 54 ms 5100 KB Output is correct
40 Correct 54 ms 4992 KB Output is correct
41 Correct 53 ms 4984 KB Output is correct
42 Correct 49 ms 4588 KB Output is correct
43 Correct 56 ms 4972 KB Output is correct
44 Correct 54 ms 4972 KB Output is correct
45 Correct 54 ms 4972 KB Output is correct
46 Correct 58 ms 5172 KB Output is correct
47 Correct 16 ms 1772 KB Output is correct
48 Correct 144 ms 11788 KB Output is correct
49 Correct 144 ms 11728 KB Output is correct
50 Correct 144 ms 11752 KB Output is correct
51 Correct 141 ms 11788 KB Output is correct
52 Correct 136 ms 11416 KB Output is correct
53 Correct 125 ms 10976 KB Output is correct
54 Correct 152 ms 12652 KB Output is correct
55 Correct 181 ms 11856 KB Output is correct
56 Correct 130 ms 11728 KB Output is correct
57 Correct 145 ms 12624 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 2 ms 364 KB Output is correct
6 Correct 2 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 52 ms 4076 KB Output is correct
11 Correct 53 ms 4844 KB Output is correct
12 Correct 54 ms 4716 KB Output is correct
13 Correct 56 ms 4972 KB Output is correct
14 Correct 56 ms 4972 KB Output is correct
15 Correct 53 ms 4204 KB Output is correct
16 Correct 142 ms 6644 KB Output is correct
17 Correct 140 ms 6684 KB Output is correct
18 Correct 144 ms 6864 KB Output is correct
19 Correct 135 ms 6864 KB Output is correct
20 Correct 115 ms 7820 KB Output is correct
21 Correct 134 ms 7892 KB Output is correct
22 Correct 119 ms 8192 KB Output is correct
23 Correct 118 ms 7760 KB Output is correct
24 Correct 119 ms 8044 KB Output is correct
25 Correct 119 ms 7832 KB Output is correct
26 Correct 119 ms 7916 KB Output is correct
27 Correct 117 ms 8124 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 10 ms 1004 KB Output is correct
38 Correct 56 ms 4972 KB Output is correct
39 Correct 53 ms 4972 KB Output is correct
40 Correct 54 ms 5100 KB Output is correct
41 Correct 54 ms 4992 KB Output is correct
42 Correct 53 ms 4984 KB Output is correct
43 Correct 49 ms 4588 KB Output is correct
44 Correct 56 ms 4972 KB Output is correct
45 Correct 54 ms 4972 KB Output is correct
46 Correct 54 ms 4972 KB Output is correct
47 Correct 58 ms 5172 KB Output is correct
48 Correct 16 ms 1772 KB Output is correct
49 Correct 144 ms 11788 KB Output is correct
50 Correct 144 ms 11728 KB Output is correct
51 Correct 144 ms 11752 KB Output is correct
52 Correct 141 ms 11788 KB Output is correct
53 Correct 136 ms 11416 KB Output is correct
54 Correct 125 ms 10976 KB Output is correct
55 Correct 152 ms 12652 KB Output is correct
56 Correct 181 ms 11856 KB Output is correct
57 Correct 130 ms 11728 KB Output is correct
58 Correct 145 ms 12624 KB Output is correct
59 Correct 76 ms 4532 KB Output is correct
60 Correct 139 ms 7784 KB Output is correct
61 Correct 146 ms 8100 KB Output is correct
62 Correct 163 ms 8272 KB Output is correct
63 Correct 128 ms 8144 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 2 ms 384 KB Output is correct
67 Correct 2 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 2 ms 364 KB Output is correct
70 Correct 2 ms 364 KB Output is correct
71 Correct 2 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 2 ms 364 KB Output is correct
74 Correct 84 ms 6124 KB Output is correct
75 Correct 54 ms 4972 KB Output is correct
76 Correct 58 ms 4972 KB Output is correct
77 Correct 61 ms 5356 KB Output is correct
78 Correct 84 ms 5356 KB Output is correct
79 Correct 72 ms 4332 KB Output is correct
80 Correct 74 ms 5356 KB Output is correct
81 Correct 95 ms 6892 KB Output is correct
82 Correct 104 ms 7532 KB Output is correct
83 Correct 117 ms 8172 KB Output is correct
84 Correct 55 ms 4972 KB Output is correct
85 Correct 105 ms 7276 KB Output is correct
86 Correct 49 ms 4596 KB Output is correct
87 Correct 154 ms 11728 KB Output is correct
88 Correct 146 ms 11728 KB Output is correct
89 Correct 140 ms 11912 KB Output is correct
90 Correct 165 ms 12484 KB Output is correct
91 Correct 161 ms 12576 KB Output is correct
92 Correct 153 ms 13000 KB Output is correct
93 Correct 193 ms 15164 KB Output is correct
94 Correct 185 ms 15820 KB Output is correct
95 Correct 213 ms 15980 KB Output is correct
96 Correct 126 ms 11792 KB Output is correct
97 Correct 161 ms 14124 KB Output is correct