답안 #583862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583862 2022-06-26T10:37:20 Z valerikk Stranded Far From Home (BOI22_island) C++17
100 / 100
355 ms 37560 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;

#define all(a) (a).begin(), (a).end()

using ll = long long;
using ld = long double;

const int N = 2e5 + 7;

int n;
int s[N];
vector<int> g[N];
int p[N];
ll sum[N];
vector<int> st[N];
int ans[N];

int get(int v) {
	return p[v] == v ? v : p[v] = get(p[v]);
}

void merge(int v, int u) {
	v = get(v);
	u = get(u);
	if (v == u) return;
	if (sum[v] > sum[u]) swap(v, u);
	p[v] = u;
	sum[u] += sum[v];
	for (int w : st[v]) {
		st[u].push_back(w);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	while (m--) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}	
	for (int i = 0; i < n; ++i) {
		ans[i] = 1;
	}
	vector<pair<int, int>> by_s;
	for (int i = 0; i < n; ++i) {
		by_s.push_back({s[i], i});
	}
	sort(all(by_s));

	for (int i = 0, j = 0; i < n; i = j) {
		vector<int> vs;
		while (j < n && by_s[j].first == by_s[i].first) {
			vs.push_back(by_s[j].second);
			++j;
		}
		for (int v : vs) {
			p[v] = v;
			sum[v] = s[v];
			st[v] = {v};
			for (int u : g[v]) {
				if (s[u] >= s[v]) continue;
				u = get(u);
				if (sum[u] >= s[v]) continue;
				while (!st[u].empty()) {
					ans[st[u].back()] = 0;
					st[u].pop_back();
				}
			}
		}
		for (int v : vs) {
			for (int u : g[v]) {
				if (s[u] <= s[v]) merge(v, u);
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << ans[i];
	}
	cout << "\n";

	return 0;	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 7 ms 9960 KB Output is correct
6 Correct 7 ms 9888 KB Output is correct
7 Correct 7 ms 9888 KB Output is correct
8 Correct 8 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 8 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9928 KB Output is correct
13 Correct 6 ms 9872 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 174 ms 30152 KB Output is correct
4 Correct 230 ms 31124 KB Output is correct
5 Correct 218 ms 30364 KB Output is correct
6 Correct 240 ms 32112 KB Output is correct
7 Correct 258 ms 30884 KB Output is correct
8 Correct 199 ms 32864 KB Output is correct
9 Correct 233 ms 34000 KB Output is correct
10 Correct 176 ms 29364 KB Output is correct
11 Correct 180 ms 31476 KB Output is correct
12 Correct 260 ms 29988 KB Output is correct
13 Correct 158 ms 31620 KB Output is correct
14 Correct 179 ms 31648 KB Output is correct
15 Correct 166 ms 29396 KB Output is correct
16 Correct 102 ms 29760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9744 KB Output is correct
2 Correct 277 ms 34700 KB Output is correct
3 Correct 286 ms 33820 KB Output is correct
4 Correct 197 ms 32160 KB Output is correct
5 Correct 186 ms 31436 KB Output is correct
6 Correct 292 ms 33076 KB Output is correct
7 Correct 235 ms 30256 KB Output is correct
8 Correct 176 ms 30308 KB Output is correct
9 Correct 112 ms 29508 KB Output is correct
10 Correct 172 ms 30472 KB Output is correct
11 Correct 208 ms 31640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 304 ms 31456 KB Output is correct
3 Correct 325 ms 32780 KB Output is correct
4 Correct 299 ms 31708 KB Output is correct
5 Correct 283 ms 37560 KB Output is correct
6 Correct 244 ms 33360 KB Output is correct
7 Correct 150 ms 32864 KB Output is correct
8 Correct 105 ms 32724 KB Output is correct
9 Correct 138 ms 21696 KB Output is correct
10 Correct 237 ms 35728 KB Output is correct
11 Correct 223 ms 30216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 7 ms 9960 KB Output is correct
6 Correct 7 ms 9888 KB Output is correct
7 Correct 7 ms 9888 KB Output is correct
8 Correct 8 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 8 ms 9940 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9928 KB Output is correct
13 Correct 6 ms 9872 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 174 ms 30152 KB Output is correct
18 Correct 230 ms 31124 KB Output is correct
19 Correct 218 ms 30364 KB Output is correct
20 Correct 240 ms 32112 KB Output is correct
21 Correct 258 ms 30884 KB Output is correct
22 Correct 199 ms 32864 KB Output is correct
23 Correct 233 ms 34000 KB Output is correct
24 Correct 176 ms 29364 KB Output is correct
25 Correct 180 ms 31476 KB Output is correct
26 Correct 260 ms 29988 KB Output is correct
27 Correct 158 ms 31620 KB Output is correct
28 Correct 179 ms 31648 KB Output is correct
29 Correct 166 ms 29396 KB Output is correct
30 Correct 102 ms 29760 KB Output is correct
31 Correct 7 ms 9744 KB Output is correct
32 Correct 277 ms 34700 KB Output is correct
33 Correct 286 ms 33820 KB Output is correct
34 Correct 197 ms 32160 KB Output is correct
35 Correct 186 ms 31436 KB Output is correct
36 Correct 292 ms 33076 KB Output is correct
37 Correct 235 ms 30256 KB Output is correct
38 Correct 176 ms 30308 KB Output is correct
39 Correct 112 ms 29508 KB Output is correct
40 Correct 172 ms 30472 KB Output is correct
41 Correct 208 ms 31640 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 304 ms 31456 KB Output is correct
44 Correct 325 ms 32780 KB Output is correct
45 Correct 299 ms 31708 KB Output is correct
46 Correct 283 ms 37560 KB Output is correct
47 Correct 244 ms 33360 KB Output is correct
48 Correct 150 ms 32864 KB Output is correct
49 Correct 105 ms 32724 KB Output is correct
50 Correct 138 ms 21696 KB Output is correct
51 Correct 237 ms 35728 KB Output is correct
52 Correct 223 ms 30216 KB Output is correct
53 Correct 5 ms 9736 KB Output is correct
54 Correct 5 ms 9732 KB Output is correct
55 Correct 5 ms 9660 KB Output is correct
56 Correct 7 ms 9812 KB Output is correct
57 Correct 8 ms 9872 KB Output is correct
58 Correct 7 ms 9892 KB Output is correct
59 Correct 7 ms 9876 KB Output is correct
60 Correct 8 ms 9788 KB Output is correct
61 Correct 7 ms 9940 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 7 ms 9940 KB Output is correct
64 Correct 8 ms 9884 KB Output is correct
65 Correct 7 ms 9940 KB Output is correct
66 Correct 7 ms 9872 KB Output is correct
67 Correct 174 ms 31212 KB Output is correct
68 Correct 188 ms 31472 KB Output is correct
69 Correct 204 ms 30836 KB Output is correct
70 Correct 226 ms 32444 KB Output is correct
71 Correct 232 ms 30820 KB Output is correct
72 Correct 202 ms 32360 KB Output is correct
73 Correct 223 ms 33940 KB Output is correct
74 Correct 195 ms 29832 KB Output is correct
75 Correct 190 ms 32608 KB Output is correct
76 Correct 216 ms 30372 KB Output is correct
77 Correct 177 ms 31672 KB Output is correct
78 Correct 181 ms 30900 KB Output is correct
79 Correct 173 ms 30848 KB Output is correct
80 Correct 110 ms 31800 KB Output is correct
81 Correct 266 ms 33476 KB Output is correct
82 Correct 293 ms 34360 KB Output is correct
83 Correct 190 ms 30604 KB Output is correct
84 Correct 187 ms 32056 KB Output is correct
85 Correct 278 ms 35840 KB Output is correct
86 Correct 172 ms 33016 KB Output is correct
87 Correct 185 ms 32976 KB Output is correct
88 Correct 179 ms 29444 KB Output is correct
89 Correct 199 ms 29300 KB Output is correct
90 Correct 301 ms 29580 KB Output is correct
91 Correct 288 ms 33608 KB Output is correct
92 Correct 307 ms 35136 KB Output is correct
93 Correct 267 ms 36644 KB Output is correct
94 Correct 244 ms 32696 KB Output is correct
95 Correct 154 ms 33488 KB Output is correct
96 Correct 108 ms 31648 KB Output is correct
97 Correct 154 ms 20828 KB Output is correct
98 Correct 298 ms 34824 KB Output is correct
99 Correct 196 ms 30868 KB Output is correct
100 Correct 68 ms 13964 KB Output is correct
101 Correct 341 ms 34156 KB Output is correct
102 Correct 201 ms 28728 KB Output is correct
103 Correct 251 ms 25780 KB Output is correct
104 Correct 355 ms 28720 KB Output is correct