# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
577319 | 2022-06-14T13:57:52 Z | jamielim | Stranded Far From Home (BOI22_island) | C++14 | 339 ms | 43172 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb emplace_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int,int> ii; typedef pair<ii,ii> i4; const int MOD=1000000007; const int INF=1012345678; const ll LLINF=1012345678012345678LL; const double PI=3.1415926536; const double EPS=1e-14; int n,m; ll s[200005]; vector<int> ordered[200005]; vector<int> adj[200005]; bool imposs[200005]; bool exist[200005]; int par[200005]; ll sz[200005]; vector<int> sets[200005]; int root(int x){ return par[x]=(par[x]==x?x:root(par[x])); } void merge(int x,int y){ int ra=root(x),rb=root(y); if(ra==rb)return; if(SZ(sets[ra])<SZ(sets[rb])){ swap(ra,rb); swap(x,y); } // rb is smaller for(int i:sets[rb])sets[ra].pb(i); sz[ra]+=sz[rb]; par[rb]=ra; } void mark_imposs(int x){ for(int i:sets[x]){ imposs[i]=1; } sets[x].clear(); } int main(){ scanf("%d%d",&n,&m); vector<ll> disc; for(int i=1;i<=n;i++){ scanf("%lld",&s[i]); disc.pb(s[i]); } sort(ALL(disc)); disc.resize(unique(ALL(disc))-disc.begin()); for(int i=1;i<=n;i++){ int x=lower_bound(ALL(disc),s[i])-disc.begin(); ordered[x].pb(i); } int a,b; for(int i=0;i<m;i++){ scanf("%d%d",&a,&b); adj[a].pb(b); adj[b].pb(a); } for(int i=1;i<=n;i++){ par[i]=i; sz[i]=s[i]; sets[i].pb(i); } for(int i=0;i<SZ(disc);i++){ for(int j:ordered[i]){ exist[j]=1; } for(int j:ordered[i]){ for(int k:adj[j]){ int p=root(k),q=root(j); if(p==q)continue; if(exist[p]){ if(sz[p]<disc[i]&&!imposs[p]){ mark_imposs(p); } merge(q,p); } } } } for(int i=1;i<=n;i++){ if(imposs[i])printf("0"); else printf("1"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 14420 KB | Output is correct |
2 | Correct | 7 ms | 14420 KB | Output is correct |
3 | Correct | 7 ms | 14292 KB | Output is correct |
4 | Correct | 8 ms | 14628 KB | Output is correct |
5 | Correct | 9 ms | 14548 KB | Output is correct |
6 | Correct | 9 ms | 14548 KB | Output is correct |
7 | Correct | 11 ms | 14620 KB | Output is correct |
8 | Correct | 11 ms | 14524 KB | Output is correct |
9 | Correct | 8 ms | 14548 KB | Output is correct |
10 | Correct | 9 ms | 14692 KB | Output is correct |
11 | Correct | 8 ms | 14676 KB | Output is correct |
12 | Correct | 8 ms | 14676 KB | Output is correct |
13 | Correct | 8 ms | 14564 KB | Output is correct |
14 | Correct | 9 ms | 14548 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14292 KB | Output is correct |
2 | Correct | 8 ms | 14384 KB | Output is correct |
3 | Correct | 200 ms | 40724 KB | Output is correct |
4 | Correct | 167 ms | 35500 KB | Output is correct |
5 | Correct | 197 ms | 41624 KB | Output is correct |
6 | Correct | 234 ms | 41272 KB | Output is correct |
7 | Correct | 229 ms | 42596 KB | Output is correct |
8 | Correct | 194 ms | 35360 KB | Output is correct |
9 | Correct | 195 ms | 42284 KB | Output is correct |
10 | Correct | 189 ms | 38712 KB | Output is correct |
11 | Correct | 155 ms | 36152 KB | Output is correct |
12 | Correct | 218 ms | 35076 KB | Output is correct |
13 | Correct | 166 ms | 35512 KB | Output is correct |
14 | Correct | 169 ms | 35468 KB | Output is correct |
15 | Correct | 176 ms | 40808 KB | Output is correct |
16 | Correct | 119 ms | 40520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 14292 KB | Output is correct |
2 | Correct | 304 ms | 43132 KB | Output is correct |
3 | Correct | 296 ms | 41984 KB | Output is correct |
4 | Correct | 177 ms | 35348 KB | Output is correct |
5 | Correct | 200 ms | 35300 KB | Output is correct |
6 | Correct | 304 ms | 43172 KB | Output is correct |
7 | Correct | 201 ms | 40844 KB | Output is correct |
8 | Correct | 195 ms | 40820 KB | Output is correct |
9 | Correct | 120 ms | 40600 KB | Output is correct |
10 | Correct | 177 ms | 37356 KB | Output is correct |
11 | Correct | 209 ms | 35676 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 14292 KB | Output is correct |
2 | Correct | 233 ms | 35680 KB | Output is correct |
3 | Correct | 228 ms | 36144 KB | Output is correct |
4 | Correct | 237 ms | 37264 KB | Output is correct |
5 | Correct | 239 ms | 37956 KB | Output is correct |
6 | Correct | 198 ms | 35584 KB | Output is correct |
7 | Correct | 153 ms | 36088 KB | Output is correct |
8 | Correct | 143 ms | 34904 KB | Output is correct |
9 | Correct | 118 ms | 25772 KB | Output is correct |
10 | Correct | 215 ms | 39588 KB | Output is correct |
11 | Correct | 188 ms | 35452 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 14420 KB | Output is correct |
2 | Correct | 7 ms | 14420 KB | Output is correct |
3 | Correct | 7 ms | 14292 KB | Output is correct |
4 | Correct | 8 ms | 14628 KB | Output is correct |
5 | Correct | 9 ms | 14548 KB | Output is correct |
6 | Correct | 9 ms | 14548 KB | Output is correct |
7 | Correct | 11 ms | 14620 KB | Output is correct |
8 | Correct | 11 ms | 14524 KB | Output is correct |
9 | Correct | 8 ms | 14548 KB | Output is correct |
10 | Correct | 9 ms | 14692 KB | Output is correct |
11 | Correct | 8 ms | 14676 KB | Output is correct |
12 | Correct | 8 ms | 14676 KB | Output is correct |
13 | Correct | 8 ms | 14564 KB | Output is correct |
14 | Correct | 9 ms | 14548 KB | Output is correct |
15 | Correct | 8 ms | 14292 KB | Output is correct |
16 | Correct | 8 ms | 14384 KB | Output is correct |
17 | Correct | 200 ms | 40724 KB | Output is correct |
18 | Correct | 167 ms | 35500 KB | Output is correct |
19 | Correct | 197 ms | 41624 KB | Output is correct |
20 | Correct | 234 ms | 41272 KB | Output is correct |
21 | Correct | 229 ms | 42596 KB | Output is correct |
22 | Correct | 194 ms | 35360 KB | Output is correct |
23 | Correct | 195 ms | 42284 KB | Output is correct |
24 | Correct | 189 ms | 38712 KB | Output is correct |
25 | Correct | 155 ms | 36152 KB | Output is correct |
26 | Correct | 218 ms | 35076 KB | Output is correct |
27 | Correct | 166 ms | 35512 KB | Output is correct |
28 | Correct | 169 ms | 35468 KB | Output is correct |
29 | Correct | 176 ms | 40808 KB | Output is correct |
30 | Correct | 119 ms | 40520 KB | Output is correct |
31 | Correct | 7 ms | 14292 KB | Output is correct |
32 | Correct | 304 ms | 43132 KB | Output is correct |
33 | Correct | 296 ms | 41984 KB | Output is correct |
34 | Correct | 177 ms | 35348 KB | Output is correct |
35 | Correct | 200 ms | 35300 KB | Output is correct |
36 | Correct | 304 ms | 43172 KB | Output is correct |
37 | Correct | 201 ms | 40844 KB | Output is correct |
38 | Correct | 195 ms | 40820 KB | Output is correct |
39 | Correct | 120 ms | 40600 KB | Output is correct |
40 | Correct | 177 ms | 37356 KB | Output is correct |
41 | Correct | 209 ms | 35676 KB | Output is correct |
42 | Correct | 7 ms | 14292 KB | Output is correct |
43 | Correct | 233 ms | 35680 KB | Output is correct |
44 | Correct | 228 ms | 36144 KB | Output is correct |
45 | Correct | 237 ms | 37264 KB | Output is correct |
46 | Correct | 239 ms | 37956 KB | Output is correct |
47 | Correct | 198 ms | 35584 KB | Output is correct |
48 | Correct | 153 ms | 36088 KB | Output is correct |
49 | Correct | 143 ms | 34904 KB | Output is correct |
50 | Correct | 118 ms | 25772 KB | Output is correct |
51 | Correct | 215 ms | 39588 KB | Output is correct |
52 | Correct | 188 ms | 35452 KB | Output is correct |
53 | Correct | 8 ms | 14420 KB | Output is correct |
54 | Correct | 9 ms | 14420 KB | Output is correct |
55 | Correct | 7 ms | 14292 KB | Output is correct |
56 | Correct | 8 ms | 14548 KB | Output is correct |
57 | Correct | 9 ms | 14672 KB | Output is correct |
58 | Correct | 8 ms | 14548 KB | Output is correct |
59 | Correct | 8 ms | 14604 KB | Output is correct |
60 | Correct | 8 ms | 14548 KB | Output is correct |
61 | Correct | 8 ms | 14616 KB | Output is correct |
62 | Correct | 9 ms | 14676 KB | Output is correct |
63 | Correct | 9 ms | 14676 KB | Output is correct |
64 | Correct | 9 ms | 14656 KB | Output is correct |
65 | Correct | 10 ms | 14548 KB | Output is correct |
66 | Correct | 9 ms | 14548 KB | Output is correct |
67 | Correct | 177 ms | 40760 KB | Output is correct |
68 | Correct | 159 ms | 35388 KB | Output is correct |
69 | Correct | 206 ms | 41656 KB | Output is correct |
70 | Correct | 220 ms | 41208 KB | Output is correct |
71 | Correct | 211 ms | 42640 KB | Output is correct |
72 | Correct | 186 ms | 35344 KB | Output is correct |
73 | Correct | 183 ms | 42324 KB | Output is correct |
74 | Correct | 233 ms | 38716 KB | Output is correct |
75 | Correct | 150 ms | 36092 KB | Output is correct |
76 | Correct | 188 ms | 34960 KB | Output is correct |
77 | Correct | 159 ms | 35524 KB | Output is correct |
78 | Correct | 159 ms | 35448 KB | Output is correct |
79 | Correct | 186 ms | 40768 KB | Output is correct |
80 | Correct | 119 ms | 40536 KB | Output is correct |
81 | Correct | 304 ms | 43104 KB | Output is correct |
82 | Correct | 291 ms | 42044 KB | Output is correct |
83 | Correct | 212 ms | 35336 KB | Output is correct |
84 | Correct | 158 ms | 35204 KB | Output is correct |
85 | Correct | 335 ms | 43128 KB | Output is correct |
86 | Correct | 195 ms | 40804 KB | Output is correct |
87 | Correct | 186 ms | 40792 KB | Output is correct |
88 | Correct | 195 ms | 37372 KB | Output is correct |
89 | Correct | 189 ms | 35624 KB | Output is correct |
90 | Correct | 241 ms | 35692 KB | Output is correct |
91 | Correct | 258 ms | 36168 KB | Output is correct |
92 | Correct | 231 ms | 37196 KB | Output is correct |
93 | Correct | 222 ms | 37872 KB | Output is correct |
94 | Correct | 208 ms | 35532 KB | Output is correct |
95 | Correct | 154 ms | 36156 KB | Output is correct |
96 | Correct | 118 ms | 34940 KB | Output is correct |
97 | Correct | 128 ms | 25708 KB | Output is correct |
98 | Correct | 241 ms | 39676 KB | Output is correct |
99 | Correct | 189 ms | 35404 KB | Output is correct |
100 | Correct | 51 ms | 16960 KB | Output is correct |
101 | Correct | 325 ms | 40448 KB | Output is correct |
102 | Correct | 175 ms | 31628 KB | Output is correct |
103 | Correct | 243 ms | 35176 KB | Output is correct |
104 | Correct | 339 ms | 40272 KB | Output is correct |