답안 #1064859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064859 2024-08-18T18:34:40 Z GusterGoose27 Security Guard (JOI23_guard) C++17
100 / 100
144 ms 16212 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5+5;
int n, m, q;

typedef long long ll;
typedef array<int, 2> ar2;

int uf[MAXN];
int val[MAXN];
ar2 edges[2*MAXN];
const int inf = 1e9;

int find(int i) {
	return uf[i] == i ? i : uf[i] = find(uf[i]);
}

int wt(ar2 i) {
	return val[i[0]] + val[i[1]];
}

struct cmp {
	bool operator()(ar2 i, ar2 j) {
		return ar2({wt(i), i[0]}) < ar2({wt(j), j[0]});
	}
} cmp;

int merge(int a, int b) {
	if (val[a] > val[b]) swap(a, b);
	uf[b] = a;
	return val[b];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	// assert(q == 0);
	iota(uf, uf+n, 0);
	ll s = 0;
	int mx = 0, mn = inf;
	for (int i = 0; i < n; i++) {
		cin >> val[i];
		s -= val[i];
		mx = max(val[i], mx);
		mn = min(val[i], mn);
	}
	s += mx;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		edges[i] = {a-1, b-1};
	}
	sort(edges, edges+m, cmp);
	vector<int> savings;
	for (int i = 0; i < m; i++) {
		int a = find(edges[i][0]);
		int b = find(edges[i][1]);
		int v = wt(edges[i]);
		if (a != b) {
			savings.push_back(v-merge(a, b)-mn);
			s += v;
		}
	}
	sort(savings.rbegin(), savings.rend());
	cout << s << '\n';
	for (int v = 0; v < q; v++) {
		s -= (v >= savings.size() ? 0 : savings[v]);
		cout << s << '\n';
	}
}

Compilation message

guard.cpp: In function 'int main()':
guard.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   s -= (v >= savings.size() ? 0 : savings[v]);
      |         ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 37 ms 6308 KB Output is correct
3 Correct 33 ms 6300 KB Output is correct
4 Correct 47 ms 6100 KB Output is correct
5 Correct 43 ms 6100 KB Output is correct
6 Correct 43 ms 6100 KB Output is correct
7 Correct 44 ms 6100 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 37 ms 6308 KB Output is correct
3 Correct 33 ms 6300 KB Output is correct
4 Correct 47 ms 6100 KB Output is correct
5 Correct 43 ms 6100 KB Output is correct
6 Correct 43 ms 6100 KB Output is correct
7 Correct 44 ms 6100 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 67 ms 6284 KB Output is correct
11 Correct 39 ms 6096 KB Output is correct
12 Correct 39 ms 6296 KB Output is correct
13 Correct 37 ms 6096 KB Output is correct
14 Correct 67 ms 6100 KB Output is correct
15 Correct 69 ms 5624 KB Output is correct
16 Correct 69 ms 6100 KB Output is correct
17 Correct 68 ms 6096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 37 ms 6308 KB Output is correct
3 Correct 33 ms 6300 KB Output is correct
4 Correct 47 ms 6100 KB Output is correct
5 Correct 43 ms 6100 KB Output is correct
6 Correct 43 ms 6100 KB Output is correct
7 Correct 44 ms 6100 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 67 ms 6284 KB Output is correct
11 Correct 39 ms 6096 KB Output is correct
12 Correct 39 ms 6296 KB Output is correct
13 Correct 37 ms 6096 KB Output is correct
14 Correct 67 ms 6100 KB Output is correct
15 Correct 69 ms 5624 KB Output is correct
16 Correct 69 ms 6100 KB Output is correct
17 Correct 68 ms 6096 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 73 ms 5624 KB Output is correct
20 Correct 72 ms 6300 KB Output is correct
21 Correct 71 ms 6100 KB Output is correct
22 Correct 76 ms 6096 KB Output is correct
23 Correct 64 ms 6100 KB Output is correct
24 Correct 64 ms 5544 KB Output is correct
25 Correct 60 ms 5584 KB Output is correct
26 Correct 58 ms 5588 KB Output is correct
27 Correct 58 ms 5588 KB Output is correct
28 Correct 73 ms 6284 KB Output is correct
29 Correct 68 ms 6100 KB Output is correct
30 Correct 61 ms 5584 KB Output is correct
31 Correct 58 ms 6104 KB Output is correct
32 Correct 68 ms 6096 KB Output is correct
33 Correct 57 ms 6120 KB Output is correct
34 Correct 60 ms 6284 KB Output is correct
35 Correct 59 ms 5584 KB Output is correct
36 Correct 56 ms 8172 KB Output is correct
37 Correct 57 ms 8144 KB Output is correct
38 Correct 63 ms 8148 KB Output is correct
39 Correct 59 ms 8460 KB Output is correct
40 Correct 59 ms 7852 KB Output is correct
41 Correct 58 ms 8144 KB Output is correct
42 Correct 72 ms 7568 KB Output is correct
43 Correct 67 ms 8360 KB Output is correct
44 Correct 72 ms 7968 KB Output is correct
45 Correct 68 ms 8400 KB Output is correct
46 Correct 79 ms 8112 KB Output is correct
47 Correct 70 ms 8052 KB Output is correct
48 Correct 74 ms 7968 KB Output is correct
49 Correct 62 ms 8180 KB Output is correct
50 Correct 71 ms 8148 KB Output is correct
51 Correct 60 ms 8152 KB Output is correct
52 Correct 53 ms 7932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 37 ms 6308 KB Output is correct
3 Correct 33 ms 6300 KB Output is correct
4 Correct 47 ms 6100 KB Output is correct
5 Correct 43 ms 6100 KB Output is correct
6 Correct 43 ms 6100 KB Output is correct
7 Correct 44 ms 6100 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 67 ms 6284 KB Output is correct
11 Correct 39 ms 6096 KB Output is correct
12 Correct 39 ms 6296 KB Output is correct
13 Correct 37 ms 6096 KB Output is correct
14 Correct 67 ms 6100 KB Output is correct
15 Correct 69 ms 5624 KB Output is correct
16 Correct 69 ms 6100 KB Output is correct
17 Correct 68 ms 6096 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 73 ms 5624 KB Output is correct
20 Correct 72 ms 6300 KB Output is correct
21 Correct 71 ms 6100 KB Output is correct
22 Correct 76 ms 6096 KB Output is correct
23 Correct 64 ms 6100 KB Output is correct
24 Correct 64 ms 5544 KB Output is correct
25 Correct 60 ms 5584 KB Output is correct
26 Correct 58 ms 5588 KB Output is correct
27 Correct 58 ms 5588 KB Output is correct
28 Correct 73 ms 6284 KB Output is correct
29 Correct 68 ms 6100 KB Output is correct
30 Correct 61 ms 5584 KB Output is correct
31 Correct 58 ms 6104 KB Output is correct
32 Correct 68 ms 6096 KB Output is correct
33 Correct 57 ms 6120 KB Output is correct
34 Correct 60 ms 6284 KB Output is correct
35 Correct 59 ms 5584 KB Output is correct
36 Correct 56 ms 8172 KB Output is correct
37 Correct 57 ms 8144 KB Output is correct
38 Correct 63 ms 8148 KB Output is correct
39 Correct 59 ms 8460 KB Output is correct
40 Correct 59 ms 7852 KB Output is correct
41 Correct 58 ms 8144 KB Output is correct
42 Correct 72 ms 7568 KB Output is correct
43 Correct 67 ms 8360 KB Output is correct
44 Correct 72 ms 7968 KB Output is correct
45 Correct 68 ms 8400 KB Output is correct
46 Correct 79 ms 8112 KB Output is correct
47 Correct 70 ms 8052 KB Output is correct
48 Correct 74 ms 7968 KB Output is correct
49 Correct 62 ms 8180 KB Output is correct
50 Correct 71 ms 8148 KB Output is correct
51 Correct 60 ms 8152 KB Output is correct
52 Correct 53 ms 7932 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 74 ms 8696 KB Output is correct
55 Correct 80 ms 8148 KB Output is correct
56 Correct 87 ms 8780 KB Output is correct
57 Correct 123 ms 10028 KB Output is correct
58 Correct 118 ms 9936 KB Output is correct
59 Correct 107 ms 10192 KB Output is correct
60 Correct 90 ms 9560 KB Output is correct
61 Correct 106 ms 9680 KB Output is correct
62 Correct 110 ms 9940 KB Output is correct
63 Correct 73 ms 8216 KB Output is correct
64 Correct 94 ms 9172 KB Output is correct
65 Correct 110 ms 9900 KB Output is correct
66 Correct 105 ms 9680 KB Output is correct
67 Correct 136 ms 9920 KB Output is correct
68 Correct 59 ms 7692 KB Output is correct
69 Correct 99 ms 9428 KB Output is correct
70 Correct 66 ms 8604 KB Output is correct
71 Correct 72 ms 8520 KB Output is correct
72 Correct 55 ms 8148 KB Output is correct
73 Correct 66 ms 8136 KB Output is correct
74 Correct 61 ms 7960 KB Output is correct
75 Correct 59 ms 7892 KB Output is correct
76 Correct 68 ms 8328 KB Output is correct
77 Correct 60 ms 7636 KB Output is correct
78 Correct 64 ms 8660 KB Output is correct
79 Correct 144 ms 10128 KB Output is correct
80 Correct 75 ms 10960 KB Output is correct
81 Correct 105 ms 12240 KB Output is correct
82 Correct 111 ms 12724 KB Output is correct
83 Correct 118 ms 12884 KB Output is correct
84 Correct 108 ms 12752 KB Output is correct
85 Correct 75 ms 9976 KB Output is correct
86 Correct 60 ms 10120 KB Output is correct
87 Correct 57 ms 8400 KB Output is correct
88 Correct 116 ms 12752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 11 ms 4700 KB Output is correct
9 Correct 12 ms 4700 KB Output is correct
10 Correct 12 ms 4444 KB Output is correct
11 Correct 14 ms 4700 KB Output is correct
12 Correct 12 ms 4692 KB Output is correct
13 Correct 11 ms 4696 KB Output is correct
14 Correct 11 ms 4700 KB Output is correct
15 Correct 11 ms 4700 KB Output is correct
16 Correct 11 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 11 ms 4700 KB Output is correct
9 Correct 12 ms 4700 KB Output is correct
10 Correct 12 ms 4444 KB Output is correct
11 Correct 14 ms 4700 KB Output is correct
12 Correct 12 ms 4692 KB Output is correct
13 Correct 11 ms 4696 KB Output is correct
14 Correct 11 ms 4700 KB Output is correct
15 Correct 11 ms 4700 KB Output is correct
16 Correct 11 ms 4700 KB Output is correct
17 Correct 16 ms 5212 KB Output is correct
18 Correct 16 ms 5212 KB Output is correct
19 Correct 27 ms 5980 KB Output is correct
20 Correct 43 ms 7508 KB Output is correct
21 Correct 51 ms 8268 KB Output is correct
22 Correct 43 ms 7508 KB Output is correct
23 Correct 87 ms 10580 KB Output is correct
24 Correct 54 ms 8788 KB Output is correct
25 Correct 12 ms 4700 KB Output is correct
26 Correct 34 ms 6784 KB Output is correct
27 Correct 16 ms 5212 KB Output is correct
28 Correct 12 ms 4700 KB Output is correct
29 Correct 15 ms 4700 KB Output is correct
30 Correct 12 ms 4700 KB Output is correct
31 Correct 10 ms 3416 KB Output is correct
32 Correct 10 ms 3420 KB Output is correct
33 Correct 12 ms 4700 KB Output is correct
34 Correct 13 ms 4952 KB Output is correct
35 Correct 29 ms 6236 KB Output is correct
36 Correct 85 ms 10580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 37 ms 6308 KB Output is correct
3 Correct 33 ms 6300 KB Output is correct
4 Correct 47 ms 6100 KB Output is correct
5 Correct 43 ms 6100 KB Output is correct
6 Correct 43 ms 6100 KB Output is correct
7 Correct 44 ms 6100 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 67 ms 6284 KB Output is correct
11 Correct 39 ms 6096 KB Output is correct
12 Correct 39 ms 6296 KB Output is correct
13 Correct 37 ms 6096 KB Output is correct
14 Correct 67 ms 6100 KB Output is correct
15 Correct 69 ms 5624 KB Output is correct
16 Correct 69 ms 6100 KB Output is correct
17 Correct 68 ms 6096 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 73 ms 5624 KB Output is correct
20 Correct 72 ms 6300 KB Output is correct
21 Correct 71 ms 6100 KB Output is correct
22 Correct 76 ms 6096 KB Output is correct
23 Correct 64 ms 6100 KB Output is correct
24 Correct 64 ms 5544 KB Output is correct
25 Correct 60 ms 5584 KB Output is correct
26 Correct 58 ms 5588 KB Output is correct
27 Correct 58 ms 5588 KB Output is correct
28 Correct 73 ms 6284 KB Output is correct
29 Correct 68 ms 6100 KB Output is correct
30 Correct 61 ms 5584 KB Output is correct
31 Correct 58 ms 6104 KB Output is correct
32 Correct 68 ms 6096 KB Output is correct
33 Correct 57 ms 6120 KB Output is correct
34 Correct 60 ms 6284 KB Output is correct
35 Correct 59 ms 5584 KB Output is correct
36 Correct 56 ms 8172 KB Output is correct
37 Correct 57 ms 8144 KB Output is correct
38 Correct 63 ms 8148 KB Output is correct
39 Correct 59 ms 8460 KB Output is correct
40 Correct 59 ms 7852 KB Output is correct
41 Correct 58 ms 8144 KB Output is correct
42 Correct 72 ms 7568 KB Output is correct
43 Correct 67 ms 8360 KB Output is correct
44 Correct 72 ms 7968 KB Output is correct
45 Correct 68 ms 8400 KB Output is correct
46 Correct 79 ms 8112 KB Output is correct
47 Correct 70 ms 8052 KB Output is correct
48 Correct 74 ms 7968 KB Output is correct
49 Correct 62 ms 8180 KB Output is correct
50 Correct 71 ms 8148 KB Output is correct
51 Correct 60 ms 8152 KB Output is correct
52 Correct 53 ms 7932 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 74 ms 8696 KB Output is correct
55 Correct 80 ms 8148 KB Output is correct
56 Correct 87 ms 8780 KB Output is correct
57 Correct 123 ms 10028 KB Output is correct
58 Correct 118 ms 9936 KB Output is correct
59 Correct 107 ms 10192 KB Output is correct
60 Correct 90 ms 9560 KB Output is correct
61 Correct 106 ms 9680 KB Output is correct
62 Correct 110 ms 9940 KB Output is correct
63 Correct 73 ms 8216 KB Output is correct
64 Correct 94 ms 9172 KB Output is correct
65 Correct 110 ms 9900 KB Output is correct
66 Correct 105 ms 9680 KB Output is correct
67 Correct 136 ms 9920 KB Output is correct
68 Correct 59 ms 7692 KB Output is correct
69 Correct 99 ms 9428 KB Output is correct
70 Correct 66 ms 8604 KB Output is correct
71 Correct 72 ms 8520 KB Output is correct
72 Correct 55 ms 8148 KB Output is correct
73 Correct 66 ms 8136 KB Output is correct
74 Correct 61 ms 7960 KB Output is correct
75 Correct 59 ms 7892 KB Output is correct
76 Correct 68 ms 8328 KB Output is correct
77 Correct 60 ms 7636 KB Output is correct
78 Correct 64 ms 8660 KB Output is correct
79 Correct 144 ms 10128 KB Output is correct
80 Correct 75 ms 10960 KB Output is correct
81 Correct 105 ms 12240 KB Output is correct
82 Correct 111 ms 12724 KB Output is correct
83 Correct 118 ms 12884 KB Output is correct
84 Correct 108 ms 12752 KB Output is correct
85 Correct 75 ms 9976 KB Output is correct
86 Correct 60 ms 10120 KB Output is correct
87 Correct 57 ms 8400 KB Output is correct
88 Correct 116 ms 12752 KB Output is correct
89 Correct 1 ms 2392 KB Output is correct
90 Correct 0 ms 2396 KB Output is correct
91 Correct 0 ms 2396 KB Output is correct
92 Correct 0 ms 2396 KB Output is correct
93 Correct 1 ms 2396 KB Output is correct
94 Correct 0 ms 2392 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 11 ms 4700 KB Output is correct
97 Correct 12 ms 4700 KB Output is correct
98 Correct 12 ms 4444 KB Output is correct
99 Correct 14 ms 4700 KB Output is correct
100 Correct 12 ms 4692 KB Output is correct
101 Correct 11 ms 4696 KB Output is correct
102 Correct 11 ms 4700 KB Output is correct
103 Correct 11 ms 4700 KB Output is correct
104 Correct 11 ms 4700 KB Output is correct
105 Correct 16 ms 5212 KB Output is correct
106 Correct 16 ms 5212 KB Output is correct
107 Correct 27 ms 5980 KB Output is correct
108 Correct 43 ms 7508 KB Output is correct
109 Correct 51 ms 8268 KB Output is correct
110 Correct 43 ms 7508 KB Output is correct
111 Correct 87 ms 10580 KB Output is correct
112 Correct 54 ms 8788 KB Output is correct
113 Correct 12 ms 4700 KB Output is correct
114 Correct 34 ms 6784 KB Output is correct
115 Correct 16 ms 5212 KB Output is correct
116 Correct 12 ms 4700 KB Output is correct
117 Correct 15 ms 4700 KB Output is correct
118 Correct 12 ms 4700 KB Output is correct
119 Correct 10 ms 3416 KB Output is correct
120 Correct 10 ms 3420 KB Output is correct
121 Correct 12 ms 4700 KB Output is correct
122 Correct 13 ms 4952 KB Output is correct
123 Correct 29 ms 6236 KB Output is correct
124 Correct 85 ms 10580 KB Output is correct
125 Correct 87 ms 12888 KB Output is correct
126 Correct 90 ms 13004 KB Output is correct
127 Correct 102 ms 13764 KB Output is correct
128 Correct 129 ms 15912 KB Output is correct
129 Correct 108 ms 15056 KB Output is correct
130 Correct 129 ms 15824 KB Output is correct
131 Correct 118 ms 15820 KB Output is correct
132 Correct 120 ms 16080 KB Output is correct
133 Correct 125 ms 15824 KB Output is correct
134 Correct 96 ms 13164 KB Output is correct
135 Correct 93 ms 13772 KB Output is correct
136 Correct 119 ms 15820 KB Output is correct
137 Correct 114 ms 16080 KB Output is correct
138 Correct 127 ms 15824 KB Output is correct
139 Correct 84 ms 11072 KB Output is correct
140 Correct 105 ms 14744 KB Output is correct
141 Correct 79 ms 13264 KB Output is correct
142 Correct 64 ms 13148 KB Output is correct
143 Correct 64 ms 13004 KB Output is correct
144 Correct 74 ms 12496 KB Output is correct
145 Correct 73 ms 12176 KB Output is correct
146 Correct 69 ms 12240 KB Output is correct
147 Correct 67 ms 11212 KB Output is correct
148 Correct 70 ms 11220 KB Output is correct
149 Correct 73 ms 12752 KB Output is correct
150 Correct 135 ms 15836 KB Output is correct
151 Correct 97 ms 14028 KB Output is correct
152 Correct 117 ms 16212 KB Output is correct
153 Correct 131 ms 16072 KB Output is correct
154 Correct 128 ms 16084 KB Output is correct
155 Correct 118 ms 15824 KB Output is correct
156 Correct 90 ms 12644 KB Output is correct
157 Correct 70 ms 13264 KB Output is correct
158 Correct 60 ms 9680 KB Output is correct
159 Correct 128 ms 15880 KB Output is correct