답안 #725624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725624 2023-04-17T19:02:25 Z WonderfulWhale Stranded Far From Home (BOI22_island) C++17
65 / 100
1000 ms 162044 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

const int MAXN = 200009;

int tab[MAXN];
vector<int> G[MAXN];
bool ans[MAXN];
map<int, vector<int>> M;
map<int, vector<int>> M2;
map<int, vector<pii>> edges;
int dependency[MAXN];

int p[MAXN];
int sum[MAXN];
multiset<pii> S[MAXN];
vector<int> cost;

int Find(int x) {
	return p[x]==x?x:p[x]=Find(p[x]);
}

void Union(int x, int y) {
	int X = Find(x);
	int Y = Find(y);
	if(X==Y) return;
	if(sz(S[X])<sz(S[Y])) swap(X, Y);
	p[Y] = X;
	sum[X] += sum[Y];
	sum[X] = min(sum[X], 1000000009);
	for(pii val:S[Y]) {
		S[X].insert(val);
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	int Max = 0;
	for(int i=1;i<=n;i++) {
		cin >> tab[i];
		M[-tab[i]].pb(i);
		M2[tab[i]].pb(i);
		Max = max(Max, tab[i]);
	}
	for(int i=0;i<m;i++) {
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
		edges[max(tab[a], tab[b])].pb({a, b});
	}
	for(int i=1;i<=n;i++) {
		p[i] = i;
		sum[i] = tab[i];
		for(int x:G[i]) {
			if(tab[x]>tab[i]) {
				S[i].insert({tab[x], x});
			}
		}
	}
	for(auto &x:M2) {
		for(pii y:edges[x.st]) {
			Union(y.st, y.nd);
		}
		for(int y:x.nd) {
			int Y = Find(y);
			auto it = S[Y].upper_bound({sum[Y], 1e9});
			if(it!=S[Y].begin()) {
				it--;
				dependency[y] = it->nd;
			}
		}
	}
	for(int x:M[-Max]) {
		ans[x] = true;
	}
	M.erase(-Max);
	for(auto &x:M) {
		for(int y:x.nd) {
			if(ans[dependency[y]]) {
				ans[y] = true;
			}
		}
	}
	for(int i=1;i<=n;i++) {
		cout << ans[i];
	}
	cout << "\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 11 ms 15316 KB Output is correct
5 Correct 12 ms 15264 KB Output is correct
6 Correct 9 ms 14548 KB Output is correct
7 Correct 10 ms 15068 KB Output is correct
8 Correct 10 ms 15060 KB Output is correct
9 Correct 8 ms 14548 KB Output is correct
10 Correct 11 ms 15444 KB Output is correct
11 Correct 13 ms 15516 KB Output is correct
12 Correct 12 ms 15572 KB Output is correct
13 Correct 11 ms 14496 KB Output is correct
14 Correct 10 ms 14804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14516 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 545 ms 111972 KB Output is correct
4 Correct 151 ms 26508 KB Output is correct
5 Correct 735 ms 134376 KB Output is correct
6 Correct 643 ms 125220 KB Output is correct
7 Correct 724 ms 139584 KB Output is correct
8 Correct 168 ms 27304 KB Output is correct
9 Correct 672 ms 157888 KB Output is correct
10 Correct 333 ms 89724 KB Output is correct
11 Correct 115 ms 28440 KB Output is correct
12 Correct 218 ms 30964 KB Output is correct
13 Correct 132 ms 26284 KB Output is correct
14 Correct 144 ms 26540 KB Output is correct
15 Correct 611 ms 108596 KB Output is correct
16 Correct 373 ms 107752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 969 ms 151960 KB Output is correct
3 Correct 846 ms 137668 KB Output is correct
4 Correct 158 ms 27052 KB Output is correct
5 Correct 139 ms 26320 KB Output is correct
6 Correct 958 ms 155740 KB Output is correct
7 Correct 593 ms 113228 KB Output is correct
8 Correct 618 ms 113288 KB Output is correct
9 Correct 356 ms 111548 KB Output is correct
10 Correct 506 ms 123744 KB Output is correct
11 Correct 421 ms 83944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 384 ms 60884 KB Output is correct
3 Correct 440 ms 65180 KB Output is correct
4 Correct 434 ms 72760 KB Output is correct
5 Correct 150 ms 27060 KB Output is correct
6 Correct 138 ms 25772 KB Output is correct
7 Correct 119 ms 28008 KB Output is correct
8 Correct 121 ms 36256 KB Output is correct
9 Correct 225 ms 48092 KB Output is correct
10 Correct 179 ms 26328 KB Output is correct
11 Correct 402 ms 78860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 11 ms 15316 KB Output is correct
5 Correct 12 ms 15264 KB Output is correct
6 Correct 9 ms 14548 KB Output is correct
7 Correct 10 ms 15068 KB Output is correct
8 Correct 10 ms 15060 KB Output is correct
9 Correct 8 ms 14548 KB Output is correct
10 Correct 11 ms 15444 KB Output is correct
11 Correct 13 ms 15516 KB Output is correct
12 Correct 12 ms 15572 KB Output is correct
13 Correct 11 ms 14496 KB Output is correct
14 Correct 10 ms 14804 KB Output is correct
15 Correct 10 ms 14516 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 545 ms 111972 KB Output is correct
18 Correct 151 ms 26508 KB Output is correct
19 Correct 735 ms 134376 KB Output is correct
20 Correct 643 ms 125220 KB Output is correct
21 Correct 724 ms 139584 KB Output is correct
22 Correct 168 ms 27304 KB Output is correct
23 Correct 672 ms 157888 KB Output is correct
24 Correct 333 ms 89724 KB Output is correct
25 Correct 115 ms 28440 KB Output is correct
26 Correct 218 ms 30964 KB Output is correct
27 Correct 132 ms 26284 KB Output is correct
28 Correct 144 ms 26540 KB Output is correct
29 Correct 611 ms 108596 KB Output is correct
30 Correct 373 ms 107752 KB Output is correct
31 Correct 8 ms 14420 KB Output is correct
32 Correct 969 ms 151960 KB Output is correct
33 Correct 846 ms 137668 KB Output is correct
34 Correct 158 ms 27052 KB Output is correct
35 Correct 139 ms 26320 KB Output is correct
36 Correct 958 ms 155740 KB Output is correct
37 Correct 593 ms 113228 KB Output is correct
38 Correct 618 ms 113288 KB Output is correct
39 Correct 356 ms 111548 KB Output is correct
40 Correct 506 ms 123744 KB Output is correct
41 Correct 421 ms 83944 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 384 ms 60884 KB Output is correct
44 Correct 440 ms 65180 KB Output is correct
45 Correct 434 ms 72760 KB Output is correct
46 Correct 150 ms 27060 KB Output is correct
47 Correct 138 ms 25772 KB Output is correct
48 Correct 119 ms 28008 KB Output is correct
49 Correct 121 ms 36256 KB Output is correct
50 Correct 225 ms 48092 KB Output is correct
51 Correct 179 ms 26328 KB Output is correct
52 Correct 402 ms 78860 KB Output is correct
53 Correct 7 ms 14420 KB Output is correct
54 Correct 7 ms 14420 KB Output is correct
55 Correct 8 ms 14432 KB Output is correct
56 Correct 11 ms 15340 KB Output is correct
57 Correct 11 ms 15316 KB Output is correct
58 Correct 8 ms 14576 KB Output is correct
59 Correct 12 ms 15212 KB Output is correct
60 Correct 11 ms 15088 KB Output is correct
61 Correct 9 ms 14620 KB Output is correct
62 Correct 11 ms 15464 KB Output is correct
63 Correct 12 ms 15596 KB Output is correct
64 Correct 12 ms 15572 KB Output is correct
65 Correct 9 ms 14496 KB Output is correct
66 Correct 10 ms 14900 KB Output is correct
67 Correct 589 ms 116412 KB Output is correct
68 Correct 155 ms 29508 KB Output is correct
69 Correct 744 ms 138588 KB Output is correct
70 Correct 702 ms 129592 KB Output is correct
71 Correct 769 ms 144080 KB Output is correct
72 Correct 169 ms 31836 KB Output is correct
73 Correct 666 ms 162044 KB Output is correct
74 Correct 376 ms 93236 KB Output is correct
75 Correct 113 ms 31812 KB Output is correct
76 Correct 185 ms 33932 KB Output is correct
77 Correct 159 ms 29192 KB Output is correct
78 Correct 147 ms 29536 KB Output is correct
79 Correct 568 ms 113356 KB Output is correct
80 Correct 354 ms 111436 KB Output is correct
81 Execution timed out 1004 ms 156384 KB Time limit exceeded
82 Halted 0 ms 0 KB -