답안 #711142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711142 2023-03-16T08:56:34 Z YeoBL Stranded Far From Home (BOI22_island) C++14
40 / 100
1000 ms 38424 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
const int MAX_N = 2e5 + 5;
bool active[MAX_N], ans[MAX_N];
int siz[MAX_N], par[MAX_N], s[MAX_N], powe[MAX_N], requ[MAX_N];
void init(int x){
	for (int i = 0; i < x; i++){
		par[i] = i;
		siz[i] = s[i];
	}
}
int head(int x){
	if (par[x] == x) return x;
	return par[x] = head(par[x]);
}
void merge(int a, int b){
	int pa = head(a), pb = head(b);
	if (pa == pb) return;
	par[pa] = pb;
	siz[pb] += siz[pa];
}
int stronk(int a){
	return siz[head(a)];
}
int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m, x, y; cin >> n >> m; 
	fill(requ, requ + n, 1e9);
	vector <int> edg[n];
	for (int i = 0; i < n; i++) cin >> s[i];
	pair <int, int> p[n];
	for (int i = 0; i < n; i++){
		p[i].fi = s[i]; p[i].se = i;
	}
	sort(p, p + n);
	for (int i = 0; i < m; i++){
		cin >> x >> y;
		x -= 1; y -= 1;
		edg[x].pb(y); edg[y].pb(x);
	}
	vector <vector <int> > v;
	for (int i = 0; i < n; i++){
		vector <int> nx;
		nx.pb(p[i].se);
		while (i != n - 1){
			if (p[i + 1].fi == p[i].fi){
				nx.pb(p[i + 1].se);
			}
			else break;
			i += 1;
		}
		v.pb(nx);
	}
	init(n);
	for (auto tmp : v){
		for (auto nd : tmp){
			active[nd] = 1;
			for (auto nx : edg[nd]){
				if (active[nx]) merge(nx, nd);
			}
		}
		for (auto nd : tmp){
			powe[nd] = stronk(nd);
		}
	}
	for (auto nd : v.back()){
		ans[nd] = 1;
	}
	for (int i = n - 1; i >= 0; i--){
		int cur = p[i].se;
		if (requ[cur] <= powe[cur]) ans[cur] = 1;
		if (!ans[cur]) continue;
		queue <int> q;
		q.push(cur);
		vector <int> x;
		while (!q.empty()){
			int curnd = q.front();
			q.pop();
			for (auto nx : edg[curnd]){
				//if (cur == 1) cerr << powe[nx] << ' ' << 
				if (s[nx] <= s[cur] and requ[nx] > s[cur] ){
					requ[nx] = min(s[cur], requ[nx]);
					q.push(nx);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 26 ms 596 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 17 ms 596 KB Output is correct
8 Correct 22 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Execution timed out 1089 ms 38424 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 490 ms 37976 KB Output is correct
3 Correct 517 ms 35952 KB Output is correct
4 Correct 206 ms 32932 KB Output is correct
5 Correct 177 ms 30348 KB Output is correct
6 Correct 649 ms 38152 KB Output is correct
7 Execution timed out 1072 ms 37800 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 359 ms 29928 KB Output is correct
3 Correct 399 ms 29884 KB Output is correct
4 Correct 294 ms 30120 KB Output is correct
5 Correct 266 ms 31296 KB Output is correct
6 Correct 264 ms 30112 KB Output is correct
7 Correct 162 ms 32868 KB Output is correct
8 Correct 108 ms 31416 KB Output is correct
9 Correct 130 ms 17932 KB Output is correct
10 Correct 210 ms 29656 KB Output is correct
11 Correct 205 ms 28064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 26 ms 596 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 17 ms 596 KB Output is correct
8 Correct 22 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Execution timed out 1089 ms 38424 KB Time limit exceeded
18 Halted 0 ms 0 KB -