답안 #578151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578151 2022-06-16T06:02:18 Z 8e7 Stranded Far From Home (BOI22_island) C++17
100 / 100
983 ms 94796 KB
//Challenge: Accepted
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...); }
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define maxc 31
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<30;
vector<int> adj[maxn];
ll sum[maxc][maxn];
int mi[maxc][maxn], comp[maxc][maxn], smi[maxc][maxn];
int idx[maxc][maxn];
int w[maxn];
int lev[maxn];
 
bool vis[maxn], tv[maxn];
void dfs(int n, int id, int l) {
	vis[n] = 1;	
	sum[l][id] += w[n];
	comp[l][n] = id;
	for (int v:adj[n]) {
		if (!vis[v] && lev[v] < l) dfs(v, id, l);
	}
}
int main() {
	io
	int n, m;
	cin >> n >> m;
	ll tot = 0;
	for (int i = 1;i <= n;i++) cin >> w[i], tot += w[i];
	for (int i = 0;i < m;i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1;i <= n;i++) {
		ll tmp = w[i];
		while (tmp >= 2) {
			lev[i]++;
			tmp >>= 1;
		}
	}
	for (int j = 0;j <= n;j++) mi[0][j] = smi[0][j] = inf;
	for (int i = 1;i < maxc;i++) {
		for (int j = 1;j <= n;j++) vis[j] = 0, mi[i][j] = smi[i][j] = inf;
		mi[i][0] = smi[i][0] = inf;
		int cnt = 1;
		for (int j = 1;j <= n;j++) {
			if (!vis[j] && lev[j] < i) {
				dfs(j, cnt, i);
				//debug(i, j, cnt, sum[i][c]);
				cnt++;
			}
		}
		for (int j = 1;j <= n;j++) {
			if (lev[j] >= i) {
				for (int k:adj[j]) {
					if (lev[k] < i) {
						int c = comp[i][k];
						if (w[j] < mi[i][c]) {
							smi[i][c] = mi[i][c];
							mi[i][c] = w[j];
							idx[i][c] = j;
						} else {
							smi[i][c] = min(smi[i][c], (int)w[j]);
						}
					}
				}
			}
		}
	}
	string ans;
	for (int i = 1;i <= n;i++) {
		int cur = lev[i];
		bool poss = 0, fi = 1;
		while (cur < maxc) {
			ll p = 0;
			int val = inf;
			if (fi) {
				fi = 0;
				p = w[i];
				vector<int> v;
				for (int j:adj[i]) {
					if (lev[j] < cur && !tv[comp[cur][j]]) {
						int c = comp[cur][j];
						tv[c] = 1;
						p += sum[cur][c];
						v.push_back(c);
						if (idx[cur][c] == i) val = min(val, smi[cur][c]);
						else val = min(val, mi[cur][c]);
					} else if (lev[j] >= cur) {
						val = min(val, (int)w[j]);
					}
				}
				for (int j:v) tv[j] = 0;
			} else {
				val = min(val, mi[cur][comp[cur][i]]);
			}
			if (comp[cur][i]) p += sum[cur][comp[cur][i]];
			//debug(cur, p, val);
			if (p == tot) {
				poss = 1;
				break;
			} else if (p < val) {
				break;
			} else {
				cur++;
			}
		}
		//debug();
		if (poss) ans += '1';
		else ans += '0';
	}
	cout << ans << "\n";
}
/*
5 4
7 10 1 5 9 
1 2 
3 5 
3 4 
4 1 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6228 KB Output is correct
6 Correct 4 ms 5716 KB Output is correct
7 Correct 5 ms 6100 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 6612 KB Output is correct
10 Correct 5 ms 6228 KB Output is correct
11 Correct 4 ms 6356 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 5 ms 6740 KB Output is correct
14 Correct 5 ms 6740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 5 ms 5812 KB Output is correct
3 Correct 245 ms 66468 KB Output is correct
4 Correct 529 ms 85376 KB Output is correct
5 Correct 290 ms 64632 KB Output is correct
6 Correct 292 ms 66508 KB Output is correct
7 Correct 320 ms 66488 KB Output is correct
8 Correct 301 ms 63712 KB Output is correct
9 Correct 285 ms 66708 KB Output is correct
10 Correct 190 ms 68328 KB Output is correct
11 Correct 203 ms 66864 KB Output is correct
12 Correct 914 ms 89364 KB Output is correct
13 Correct 533 ms 90732 KB Output is correct
14 Correct 542 ms 88700 KB Output is correct
15 Correct 241 ms 69752 KB Output is correct
16 Correct 168 ms 78832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 280 ms 79032 KB Output is correct
3 Correct 259 ms 79580 KB Output is correct
4 Correct 247 ms 68508 KB Output is correct
5 Correct 636 ms 90852 KB Output is correct
6 Correct 325 ms 79192 KB Output is correct
7 Correct 219 ms 68540 KB Output is correct
8 Correct 230 ms 68540 KB Output is correct
9 Correct 163 ms 78812 KB Output is correct
10 Correct 422 ms 81756 KB Output is correct
11 Correct 649 ms 94356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 402 ms 69252 KB Output is correct
3 Correct 343 ms 72796 KB Output is correct
4 Correct 369 ms 66220 KB Output is correct
5 Correct 287 ms 63800 KB Output is correct
6 Correct 263 ms 61136 KB Output is correct
7 Correct 186 ms 63756 KB Output is correct
8 Correct 181 ms 82312 KB Output is correct
9 Correct 357 ms 47428 KB Output is correct
10 Correct 983 ms 85216 KB Output is correct
11 Correct 527 ms 94448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 4 ms 6100 KB Output is correct
5 Correct 4 ms 6228 KB Output is correct
6 Correct 4 ms 5716 KB Output is correct
7 Correct 5 ms 6100 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 6612 KB Output is correct
10 Correct 5 ms 6228 KB Output is correct
11 Correct 4 ms 6356 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 5 ms 6740 KB Output is correct
14 Correct 5 ms 6740 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 5 ms 5812 KB Output is correct
17 Correct 245 ms 66468 KB Output is correct
18 Correct 529 ms 85376 KB Output is correct
19 Correct 290 ms 64632 KB Output is correct
20 Correct 292 ms 66508 KB Output is correct
21 Correct 320 ms 66488 KB Output is correct
22 Correct 301 ms 63712 KB Output is correct
23 Correct 285 ms 66708 KB Output is correct
24 Correct 190 ms 68328 KB Output is correct
25 Correct 203 ms 66864 KB Output is correct
26 Correct 914 ms 89364 KB Output is correct
27 Correct 533 ms 90732 KB Output is correct
28 Correct 542 ms 88700 KB Output is correct
29 Correct 241 ms 69752 KB Output is correct
30 Correct 168 ms 78832 KB Output is correct
31 Correct 3 ms 5716 KB Output is correct
32 Correct 280 ms 79032 KB Output is correct
33 Correct 259 ms 79580 KB Output is correct
34 Correct 247 ms 68508 KB Output is correct
35 Correct 636 ms 90852 KB Output is correct
36 Correct 325 ms 79192 KB Output is correct
37 Correct 219 ms 68540 KB Output is correct
38 Correct 230 ms 68540 KB Output is correct
39 Correct 163 ms 78812 KB Output is correct
40 Correct 422 ms 81756 KB Output is correct
41 Correct 649 ms 94356 KB Output is correct
42 Correct 3 ms 5716 KB Output is correct
43 Correct 402 ms 69252 KB Output is correct
44 Correct 343 ms 72796 KB Output is correct
45 Correct 369 ms 66220 KB Output is correct
46 Correct 287 ms 63800 KB Output is correct
47 Correct 263 ms 61136 KB Output is correct
48 Correct 186 ms 63756 KB Output is correct
49 Correct 181 ms 82312 KB Output is correct
50 Correct 357 ms 47428 KB Output is correct
51 Correct 983 ms 85216 KB Output is correct
52 Correct 527 ms 94448 KB Output is correct
53 Correct 3 ms 5716 KB Output is correct
54 Correct 3 ms 5716 KB Output is correct
55 Correct 3 ms 5716 KB Output is correct
56 Correct 5 ms 6100 KB Output is correct
57 Correct 5 ms 6228 KB Output is correct
58 Correct 4 ms 5716 KB Output is correct
59 Correct 4 ms 6100 KB Output is correct
60 Correct 5 ms 5972 KB Output is correct
61 Correct 4 ms 6612 KB Output is correct
62 Correct 4 ms 6228 KB Output is correct
63 Correct 4 ms 6356 KB Output is correct
64 Correct 4 ms 6112 KB Output is correct
65 Correct 5 ms 6740 KB Output is correct
66 Correct 5 ms 6740 KB Output is correct
67 Correct 273 ms 66384 KB Output is correct
68 Correct 486 ms 85420 KB Output is correct
69 Correct 309 ms 64692 KB Output is correct
70 Correct 289 ms 66356 KB Output is correct
71 Correct 281 ms 66484 KB Output is correct
72 Correct 294 ms 63664 KB Output is correct
73 Correct 242 ms 66680 KB Output is correct
74 Correct 210 ms 68440 KB Output is correct
75 Correct 193 ms 66852 KB Output is correct
76 Correct 862 ms 89452 KB Output is correct
77 Correct 566 ms 90812 KB Output is correct
78 Correct 525 ms 88724 KB Output is correct
79 Correct 263 ms 69828 KB Output is correct
80 Correct 170 ms 78876 KB Output is correct
81 Correct 269 ms 79068 KB Output is correct
82 Correct 259 ms 79428 KB Output is correct
83 Correct 251 ms 68516 KB Output is correct
84 Correct 541 ms 90724 KB Output is correct
85 Correct 294 ms 79128 KB Output is correct
86 Correct 230 ms 68444 KB Output is correct
87 Correct 245 ms 68444 KB Output is correct
88 Correct 413 ms 81716 KB Output is correct
89 Correct 551 ms 94544 KB Output is correct
90 Correct 394 ms 69300 KB Output is correct
91 Correct 370 ms 72756 KB Output is correct
92 Correct 323 ms 66272 KB Output is correct
93 Correct 352 ms 63736 KB Output is correct
94 Correct 286 ms 61220 KB Output is correct
95 Correct 191 ms 63816 KB Output is correct
96 Correct 198 ms 82172 KB Output is correct
97 Correct 402 ms 47404 KB Output is correct
98 Correct 953 ms 85340 KB Output is correct
99 Correct 592 ms 94796 KB Output is correct
100 Correct 58 ms 9108 KB Output is correct
101 Correct 383 ms 73140 KB Output is correct
102 Correct 236 ms 52932 KB Output is correct
103 Correct 287 ms 63760 KB Output is correct
104 Correct 428 ms 73172 KB Output is correct