답안 #604198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604198 2022-07-24T20:38:06 Z DanerZein Stranded Far From Home (BOI22_island) C++14
15 / 100
444 ms 25444 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int MAX_N=2e5+10;
vector<vi> G;
ll ha[MAX_N];
bool vis[MAX_N];
int n,m;
void bfs(int u){
  for(int i=0;i<n;i++) vis[i]=0;
  priority_queue<ii, vector<ii>, greater<ii> > q;
  vis[u]=1; 
  ll co=ha[u];
  for(auto &v:G[u]){
    q.push(ii(ha[v],v));
  }
  while(!q.empty()){
    int x=q.top().second; q.pop();
    if(co<ha[x]) continue;
    vis[x]=1;
    co+=ha[x];
    for(auto &v:G[x]){
      if(!vis[v]){
        q.push(ii(ha[v],v));
      }
    }
  }
}
int pa[MAX_N];
ll sb[MAX_N];
void dfs(int u,int p){
  pa[u]=p;
  sb[u]=ha[u];
  for(auto &v:G[u]){
    if(v!=p){
      dfs(v,u);
      sb[u]+=sb[v];
    }
  }
}
ll sum[MAX_N];
bool habitant(int a,int b){
  return ha[a]>ha[b];
}
int main(){
  cin>>n>>m;
  G.resize(n+1);
  for(int i=0;i<n;i++) cin>>ha[i];
  for(int i=0;i<m;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  string ans="";
  ans.resize(n);
  sum[0]=ha[0];
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+ha[i];
  }
  vector<int> mah;
  for(int i=0;i<n;i++) mah.push_back(i);
  sort(mah.begin(),mah.end(),habitant);
  set<int> lim;
  lim.insert(-1); lim.insert(mah[0]); lim.insert(n);
  ans[mah[0]]='1';
  for(int i=1;i<n;i++){
    auto it=lim.lower_bound(mah[i]);
    int r=(*it); it--;
    int l=(*it);
    ll sr=sum[r-1];
    ll sl=0;
    if(l!=-1) sl=sum[l];
    ll s=sr-sl;
    //cout<<mah[i]<<" "<<l<<" "<<r<<" "<<s<<endl;
    if(l!=-1 && s>=ha[l]) ans[mah[i]]=ans[l];
    else if(r!=n && s>=ha[r]) ans[mah[i]]=ans[r];
    else ans[mah[i]]='0';
    lim.insert(mah[i]);
  }
  /*if(n>2000){
    ans="1";
    dfs(0,0);
    for(int i=1;i<n;i++){
      if(sb[i]>=ha[pa[i]] && ans[pa[i]]=='1') ans+='1';
      else ans+='0';
    }
  }
  else{
    for(int i=0;i<n;i++){
      bfs(i);
      bool all=1;
      for(int j=0;j<n;j++) all&=vis[j];
      if(all) ans+='1';
      else ans+='0';
    }
    }*/
  cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Incorrect 4 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 335 ms 25444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 381 ms 24812 KB Output is correct
3 Correct 400 ms 25196 KB Output is correct
4 Correct 305 ms 25172 KB Output is correct
5 Correct 237 ms 25204 KB Output is correct
6 Correct 444 ms 25124 KB Output is correct
7 Correct 315 ms 25108 KB Output is correct
8 Correct 337 ms 25208 KB Output is correct
9 Correct 278 ms 24968 KB Output is correct
10 Correct 254 ms 25188 KB Output is correct
11 Correct 284 ms 25212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 316 ms 24884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Incorrect 4 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -