답안 #1099397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099397 2024-10-11T09:13:29 Z epicci23 Stranded Far From Home (BOI22_island) C++17
100 / 100
455 ms 80232 KB
#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;

const int N = 2e5 + 5;
int s[N],par[N],val[N];
vector<int> v[N],comp[N];
bool open[N],ans[N];
priority_queue<int> pq[N];

int find(int a){
  if(par[a]==a) return a;
  return par[a]=find(par[a]);
}

void unite(int a,int b){
  a=find(a),b=find(b);
  if(a==b) return;
  if(sz(comp[a])>sz(comp[b])) swap(a,b);
  val[b]+=val[a];
  par[a]=b;
  for(int x:comp[a]) comp[b].push_back(x);
  comp[a].clear();
  while(!pq[a].empty()){
  	pq[b].push(pq[a].top());
  	pq[a].pop();
  }
}

void _(){
  int n,m;
  cin >> n >> m;
  iota(par,par+N,0LL);
  for(int i=1;i<=n;i++) comp[i].push_back(i);
  for(int i=1;i<=n;i++){
  	cin >> s[i];
  	val[i]+=s[i];
  }
  for(int i=1;i<=m;i++){
  	int a,b;
  	cin >> a >> b;
  	v[a].push_back(b);
  	v[b].push_back(a);
  }

  map<int,vector<int>> lol;
  for(int i=1;i<=n;i++) lol[s[i]].push_back(i);
  for(int i=1;i<=n;i++) for(int x:v[i]) pq[i].push(-s[x]);
  
  for(auto i:lol){
   
    for(int u:i.second) open[u]=1;
    for(int u:i.second){
      for(int x:v[u]){
        if(!open[x]) continue;
        unite(u,x);
      }
    }
    
    vector<int> cur;
    for(int u:i.second) cur.push_back(find(u));
    sort(all(cur));
    cur.erase(unique(all(cur)),cur.end());
    
    for(int u:cur){
     while(!pq[u].empty() && pq[u].top()*-1<=i.first) pq[u].pop();
     if(pq[u].empty()){
      for(int x:comp[u]) ans[x]=1;
      comp[u].clear();
     }
     else if(!pq[u].empty() && pq[u].top()*-1>val[u]){
      for(int x:comp[u]) ans[x]=0;
      comp[u].clear();	
     }
    }
  }

  for(int i=1;i<=n;i++) cout << ans[i];
  cout << '\n';
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17496 KB Output is correct
2 Correct 11 ms 17500 KB Output is correct
3 Correct 9 ms 17660 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 8 ms 18012 KB Output is correct
6 Correct 8 ms 18008 KB Output is correct
7 Correct 8 ms 17932 KB Output is correct
8 Correct 10 ms 18008 KB Output is correct
9 Correct 8 ms 18012 KB Output is correct
10 Correct 9 ms 18036 KB Output is correct
11 Correct 11 ms 18268 KB Output is correct
12 Correct 8 ms 18008 KB Output is correct
13 Correct 9 ms 17932 KB Output is correct
14 Correct 11 ms 17932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17500 KB Output is correct
2 Correct 9 ms 17904 KB Output is correct
3 Correct 214 ms 71876 KB Output is correct
4 Correct 137 ms 55816 KB Output is correct
5 Correct 224 ms 73924 KB Output is correct
6 Correct 209 ms 70956 KB Output is correct
7 Correct 230 ms 75740 KB Output is correct
8 Correct 172 ms 58556 KB Output is correct
9 Correct 230 ms 74688 KB Output is correct
10 Correct 209 ms 70716 KB Output is correct
11 Correct 154 ms 57908 KB Output is correct
12 Correct 191 ms 56384 KB Output is correct
13 Correct 134 ms 54716 KB Output is correct
14 Correct 138 ms 54336 KB Output is correct
15 Correct 180 ms 68204 KB Output is correct
16 Correct 154 ms 67016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17496 KB Output is correct
2 Correct 362 ms 76544 KB Output is correct
3 Correct 376 ms 72284 KB Output is correct
4 Correct 151 ms 56348 KB Output is correct
5 Correct 143 ms 55476 KB Output is correct
6 Correct 421 ms 76828 KB Output is correct
7 Correct 167 ms 68108 KB Output is correct
8 Correct 177 ms 68152 KB Output is correct
9 Correct 190 ms 67016 KB Output is correct
10 Correct 174 ms 64388 KB Output is correct
11 Correct 187 ms 53652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 17500 KB Output is correct
2 Correct 252 ms 57112 KB Output is correct
3 Correct 231 ms 57556 KB Output is correct
4 Correct 246 ms 60428 KB Output is correct
5 Correct 275 ms 77160 KB Output is correct
6 Correct 241 ms 67772 KB Output is correct
7 Correct 159 ms 58160 KB Output is correct
8 Correct 120 ms 56616 KB Output is correct
9 Correct 149 ms 42860 KB Output is correct
10 Correct 254 ms 80232 KB Output is correct
11 Correct 242 ms 52692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17496 KB Output is correct
2 Correct 11 ms 17500 KB Output is correct
3 Correct 9 ms 17660 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 8 ms 18012 KB Output is correct
6 Correct 8 ms 18008 KB Output is correct
7 Correct 8 ms 17932 KB Output is correct
8 Correct 10 ms 18008 KB Output is correct
9 Correct 8 ms 18012 KB Output is correct
10 Correct 9 ms 18036 KB Output is correct
11 Correct 11 ms 18268 KB Output is correct
12 Correct 8 ms 18008 KB Output is correct
13 Correct 9 ms 17932 KB Output is correct
14 Correct 11 ms 17932 KB Output is correct
15 Correct 9 ms 17500 KB Output is correct
16 Correct 9 ms 17904 KB Output is correct
17 Correct 214 ms 71876 KB Output is correct
18 Correct 137 ms 55816 KB Output is correct
19 Correct 224 ms 73924 KB Output is correct
20 Correct 209 ms 70956 KB Output is correct
21 Correct 230 ms 75740 KB Output is correct
22 Correct 172 ms 58556 KB Output is correct
23 Correct 230 ms 74688 KB Output is correct
24 Correct 209 ms 70716 KB Output is correct
25 Correct 154 ms 57908 KB Output is correct
26 Correct 191 ms 56384 KB Output is correct
27 Correct 134 ms 54716 KB Output is correct
28 Correct 138 ms 54336 KB Output is correct
29 Correct 180 ms 68204 KB Output is correct
30 Correct 154 ms 67016 KB Output is correct
31 Correct 9 ms 17496 KB Output is correct
32 Correct 362 ms 76544 KB Output is correct
33 Correct 376 ms 72284 KB Output is correct
34 Correct 151 ms 56348 KB Output is correct
35 Correct 143 ms 55476 KB Output is correct
36 Correct 421 ms 76828 KB Output is correct
37 Correct 167 ms 68108 KB Output is correct
38 Correct 177 ms 68152 KB Output is correct
39 Correct 190 ms 67016 KB Output is correct
40 Correct 174 ms 64388 KB Output is correct
41 Correct 187 ms 53652 KB Output is correct
42 Correct 7 ms 17500 KB Output is correct
43 Correct 252 ms 57112 KB Output is correct
44 Correct 231 ms 57556 KB Output is correct
45 Correct 246 ms 60428 KB Output is correct
46 Correct 275 ms 77160 KB Output is correct
47 Correct 241 ms 67772 KB Output is correct
48 Correct 159 ms 58160 KB Output is correct
49 Correct 120 ms 56616 KB Output is correct
50 Correct 149 ms 42860 KB Output is correct
51 Correct 254 ms 80232 KB Output is correct
52 Correct 242 ms 52692 KB Output is correct
53 Correct 8 ms 17496 KB Output is correct
54 Correct 10 ms 17496 KB Output is correct
55 Correct 9 ms 17500 KB Output is correct
56 Correct 11 ms 18012 KB Output is correct
57 Correct 9 ms 18008 KB Output is correct
58 Correct 14 ms 18008 KB Output is correct
59 Correct 16 ms 18012 KB Output is correct
60 Correct 11 ms 18008 KB Output is correct
61 Correct 11 ms 18012 KB Output is correct
62 Correct 16 ms 18188 KB Output is correct
63 Correct 10 ms 18268 KB Output is correct
64 Correct 10 ms 18252 KB Output is correct
65 Correct 9 ms 18012 KB Output is correct
66 Correct 15 ms 18012 KB Output is correct
67 Correct 254 ms 71824 KB Output is correct
68 Correct 176 ms 55756 KB Output is correct
69 Correct 281 ms 73844 KB Output is correct
70 Correct 321 ms 70940 KB Output is correct
71 Correct 305 ms 75844 KB Output is correct
72 Correct 258 ms 58528 KB Output is correct
73 Correct 209 ms 74688 KB Output is correct
74 Correct 261 ms 70712 KB Output is correct
75 Correct 159 ms 57904 KB Output is correct
76 Correct 206 ms 56440 KB Output is correct
77 Correct 153 ms 54708 KB Output is correct
78 Correct 143 ms 54340 KB Output is correct
79 Correct 171 ms 68036 KB Output is correct
80 Correct 208 ms 67032 KB Output is correct
81 Correct 428 ms 76544 KB Output is correct
82 Correct 406 ms 72384 KB Output is correct
83 Correct 150 ms 56344 KB Output is correct
84 Correct 138 ms 55480 KB Output is correct
85 Correct 455 ms 76996 KB Output is correct
86 Correct 205 ms 68236 KB Output is correct
87 Correct 168 ms 68292 KB Output is correct
88 Correct 166 ms 64320 KB Output is correct
89 Correct 192 ms 53648 KB Output is correct
90 Correct 286 ms 57148 KB Output is correct
91 Correct 257 ms 57560 KB Output is correct
92 Correct 261 ms 60432 KB Output is correct
93 Correct 263 ms 77124 KB Output is correct
94 Correct 242 ms 67772 KB Output is correct
95 Correct 132 ms 58048 KB Output is correct
96 Correct 106 ms 56620 KB Output is correct
97 Correct 149 ms 42808 KB Output is correct
98 Correct 275 ms 80084 KB Output is correct
99 Correct 153 ms 52556 KB Output is correct
100 Correct 90 ms 29460 KB Output is correct
101 Correct 372 ms 70604 KB Output is correct
102 Correct 195 ms 59580 KB Output is correct
103 Correct 299 ms 62020 KB Output is correct
104 Correct 370 ms 73180 KB Output is correct