답안 #586901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586901 2022-06-30T23:23:45 Z nots0fast Stranded Far From Home (BOI22_island) C++17
100 / 100
379 ms 91640 KB
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define mt make_tuple
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define ll long long
#define lll __int128
#define ld long double
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll modulo = 1000000007;
double eps = 1e-10;
ifstream in;
ofstream out;

#define MAX (int)(pow(10,6) + 10)

ll arr[MAX];

namespace n10{
	int aid[MAX];
	vector<int> dsu[MAX];
	vector<int> good[MAX];
	ll s[MAX];
	void ini(int n){
		fori(n)
			aid[i] = i, dsu[i].clear(), dsu[i].push_back(i), good[i].pb(i), s[i] = arr[i];
	}
	bool join(int a,int b){  //	1 - if joined, 0 - if they were already joined 
		int aid1 = aid[a], aid2 = aid[b];
		if(dsu[aid2].size() > dsu[aid1].size())
			swap(aid1,aid2);
		if(aid1==aid2)
			return 0;
		for(auto hd : dsu[aid2]){
			aid[hd] = aid1;
			dsu[aid1].push_back(hd);
		}
		for(auto& hd : good[aid2]){
			good[aid1].pb(hd);
		}
		
		dsu[aid2].clear();
		good[aid2].clear();
		s[aid1]+=s[aid2];
		return 1;
	}
};

using namespace n10;

bool srt(ll i, ll j){
	return arr[i] < arr[j];
}

void deal(){
	ll n, m;
	cin>>n>>m;
	
	vector<vector<ll> > g(n);
	fori(n){
		cin>>arr[i];
	}
	
	ini(n);
	
	fori(m){
		ll ai, bi;
		cin>>ai>>bi;
		--ai, --bi;
		g[ai].pb(bi);
		g[bi].pb(ai);
	}
	
	vector<ll > all;
	fori(n){
		all.pb(i);
	}
	
	sort(all.begin(), all.end(), srt);
	fori(n){
		sort(g[i].begin(), g[i].end(), srt);
	}
	
	for(auto& hd : all){
		for(auto& hr : g[hd]){
			ll aid2 = aid[hr];
			ll aid1 = aid[hd];
			if(s[aid2] < arr[hd]){
			//	cout<<"bad for "<<hr+1<<" because "<<hd+1<<" "<<arr[hd]<<endl;
				good[aid2].clear();
			}
			if(arr[hr] <= s[aid1]){
				join(hr, hd);
			}
		}
	}
	
	ll wh = aid[0];
	vector<bool> ans(n, 0);
	for(auto& el : good[wh]){
		ans[el] = 1;
	}
	
	fori(n){
		cout<<ans[i];
	}
	
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47188 KB Output is correct
2 Correct 25 ms 47200 KB Output is correct
3 Correct 25 ms 47204 KB Output is correct
4 Correct 27 ms 47504 KB Output is correct
5 Correct 31 ms 47604 KB Output is correct
6 Correct 27 ms 47592 KB Output is correct
7 Correct 26 ms 47572 KB Output is correct
8 Correct 29 ms 47540 KB Output is correct
9 Correct 26 ms 47656 KB Output is correct
10 Correct 28 ms 47780 KB Output is correct
11 Correct 33 ms 47596 KB Output is correct
12 Correct 26 ms 47644 KB Output is correct
13 Correct 26 ms 47556 KB Output is correct
14 Correct 30 ms 47640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47272 KB Output is correct
2 Correct 25 ms 47200 KB Output is correct
3 Correct 261 ms 80896 KB Output is correct
4 Correct 232 ms 85916 KB Output is correct
5 Correct 266 ms 85528 KB Output is correct
6 Correct 326 ms 86200 KB Output is correct
7 Correct 307 ms 86204 KB Output is correct
8 Correct 327 ms 83664 KB Output is correct
9 Correct 237 ms 91640 KB Output is correct
10 Correct 189 ms 79756 KB Output is correct
11 Correct 186 ms 80952 KB Output is correct
12 Correct 276 ms 82680 KB Output is correct
13 Correct 240 ms 86408 KB Output is correct
14 Correct 208 ms 85172 KB Output is correct
15 Correct 190 ms 79324 KB Output is correct
16 Correct 142 ms 79036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47184 KB Output is correct
2 Correct 299 ms 87576 KB Output is correct
3 Correct 302 ms 87288 KB Output is correct
4 Correct 216 ms 86428 KB Output is correct
5 Correct 242 ms 87156 KB Output is correct
6 Correct 322 ms 87344 KB Output is correct
7 Correct 243 ms 79364 KB Output is correct
8 Correct 265 ms 79372 KB Output is correct
9 Correct 139 ms 79040 KB Output is correct
10 Correct 216 ms 82972 KB Output is correct
11 Correct 263 ms 86000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47268 KB Output is correct
2 Correct 347 ms 82624 KB Output is correct
3 Correct 316 ms 83360 KB Output is correct
4 Correct 367 ms 85152 KB Output is correct
5 Correct 306 ms 86012 KB Output is correct
6 Correct 310 ms 81948 KB Output is correct
7 Correct 190 ms 81080 KB Output is correct
8 Correct 157 ms 83616 KB Output is correct
9 Correct 192 ms 66248 KB Output is correct
10 Correct 338 ms 87556 KB Output is correct
11 Correct 268 ms 86184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47188 KB Output is correct
2 Correct 25 ms 47200 KB Output is correct
3 Correct 25 ms 47204 KB Output is correct
4 Correct 27 ms 47504 KB Output is correct
5 Correct 31 ms 47604 KB Output is correct
6 Correct 27 ms 47592 KB Output is correct
7 Correct 26 ms 47572 KB Output is correct
8 Correct 29 ms 47540 KB Output is correct
9 Correct 26 ms 47656 KB Output is correct
10 Correct 28 ms 47780 KB Output is correct
11 Correct 33 ms 47596 KB Output is correct
12 Correct 26 ms 47644 KB Output is correct
13 Correct 26 ms 47556 KB Output is correct
14 Correct 30 ms 47640 KB Output is correct
15 Correct 25 ms 47272 KB Output is correct
16 Correct 25 ms 47200 KB Output is correct
17 Correct 261 ms 80896 KB Output is correct
18 Correct 232 ms 85916 KB Output is correct
19 Correct 266 ms 85528 KB Output is correct
20 Correct 326 ms 86200 KB Output is correct
21 Correct 307 ms 86204 KB Output is correct
22 Correct 327 ms 83664 KB Output is correct
23 Correct 237 ms 91640 KB Output is correct
24 Correct 189 ms 79756 KB Output is correct
25 Correct 186 ms 80952 KB Output is correct
26 Correct 276 ms 82680 KB Output is correct
27 Correct 240 ms 86408 KB Output is correct
28 Correct 208 ms 85172 KB Output is correct
29 Correct 190 ms 79324 KB Output is correct
30 Correct 142 ms 79036 KB Output is correct
31 Correct 25 ms 47184 KB Output is correct
32 Correct 299 ms 87576 KB Output is correct
33 Correct 302 ms 87288 KB Output is correct
34 Correct 216 ms 86428 KB Output is correct
35 Correct 242 ms 87156 KB Output is correct
36 Correct 322 ms 87344 KB Output is correct
37 Correct 243 ms 79364 KB Output is correct
38 Correct 265 ms 79372 KB Output is correct
39 Correct 139 ms 79040 KB Output is correct
40 Correct 216 ms 82972 KB Output is correct
41 Correct 263 ms 86000 KB Output is correct
42 Correct 25 ms 47268 KB Output is correct
43 Correct 347 ms 82624 KB Output is correct
44 Correct 316 ms 83360 KB Output is correct
45 Correct 367 ms 85152 KB Output is correct
46 Correct 306 ms 86012 KB Output is correct
47 Correct 310 ms 81948 KB Output is correct
48 Correct 190 ms 81080 KB Output is correct
49 Correct 157 ms 83616 KB Output is correct
50 Correct 192 ms 66248 KB Output is correct
51 Correct 338 ms 87556 KB Output is correct
52 Correct 268 ms 86184 KB Output is correct
53 Correct 27 ms 47256 KB Output is correct
54 Correct 28 ms 47308 KB Output is correct
55 Correct 33 ms 47284 KB Output is correct
56 Correct 29 ms 47572 KB Output is correct
57 Correct 26 ms 47588 KB Output is correct
58 Correct 26 ms 47548 KB Output is correct
59 Correct 27 ms 47512 KB Output is correct
60 Correct 26 ms 47444 KB Output is correct
61 Correct 27 ms 47580 KB Output is correct
62 Correct 27 ms 47576 KB Output is correct
63 Correct 28 ms 47608 KB Output is correct
64 Correct 29 ms 47636 KB Output is correct
65 Correct 28 ms 47652 KB Output is correct
66 Correct 27 ms 47588 KB Output is correct
67 Correct 202 ms 80828 KB Output is correct
68 Correct 229 ms 85920 KB Output is correct
69 Correct 295 ms 85576 KB Output is correct
70 Correct 349 ms 86200 KB Output is correct
71 Correct 280 ms 86176 KB Output is correct
72 Correct 346 ms 83712 KB Output is correct
73 Correct 224 ms 91552 KB Output is correct
74 Correct 174 ms 79760 KB Output is correct
75 Correct 214 ms 80932 KB Output is correct
76 Correct 279 ms 82708 KB Output is correct
77 Correct 214 ms 86440 KB Output is correct
78 Correct 226 ms 85100 KB Output is correct
79 Correct 266 ms 79344 KB Output is correct
80 Correct 139 ms 79036 KB Output is correct
81 Correct 327 ms 87568 KB Output is correct
82 Correct 321 ms 87396 KB Output is correct
83 Correct 227 ms 86472 KB Output is correct
84 Correct 207 ms 87256 KB Output is correct
85 Correct 321 ms 87424 KB Output is correct
86 Correct 214 ms 79392 KB Output is correct
87 Correct 252 ms 79396 KB Output is correct
88 Correct 202 ms 82764 KB Output is correct
89 Correct 249 ms 85952 KB Output is correct
90 Correct 379 ms 82492 KB Output is correct
91 Correct 313 ms 83500 KB Output is correct
92 Correct 343 ms 85160 KB Output is correct
93 Correct 310 ms 86080 KB Output is correct
94 Correct 302 ms 81888 KB Output is correct
95 Correct 184 ms 80884 KB Output is correct
96 Correct 156 ms 83700 KB Output is correct
97 Correct 187 ms 66284 KB Output is correct
98 Correct 318 ms 87452 KB Output is correct
99 Correct 292 ms 86212 KB Output is correct
100 Correct 80 ms 52300 KB Output is correct
101 Correct 360 ms 84732 KB Output is correct
102 Correct 257 ms 76196 KB Output is correct
103 Correct 287 ms 76548 KB Output is correct
104 Correct 324 ms 81544 KB Output is correct