답안 #604243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604243 2022-07-24T23:17:54 Z DanerZein Stranded Far From Home (BOI22_island) C++14
40 / 100
1000 ms 30904 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];
bool ans[MAX_N];
int n,m;
vector<int> cma;
vector<int> con;
ll dfs(int u,int ma){
  if(ma==ha[u])
    con.push_back(u);
  vis[u]=1;
  ll s=ha[u];
  for(auto &v:G[u]){
    if(ma<ha[v]){
      cma.push_back(v);
    }
    else{
      if(!vis[v]){
	s+=dfs(v,ma);
      }
    }
  }
  return s;
}
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);
  }
  vector<int> dh;
  for(int i=0;i<n;i++){
    dh.push_back(ha[i]);
  }
  sort(dh.begin(),dh.end());
  dh.erase(unique(dh.begin(),dh.end()),dh.end());
  reverse(dh.begin(),dh.end());
  for(int i=0;i<n;i++){
    if(ha[i]==dh[0])
      ans[i]=1;
  }
  for(int h=1;h<dh.size();h++){
    int v=dh[h];
    memset(vis,0,sizeof vis);
    for(int i=0;i<n;i++){
      if(!vis[i] && ha[i]==v){
	con.clear();
	cma.clear();
	ll s=dfs(i,v);
	bool ok=0;
	for(int j=0;j<cma.size();j++){
	  if(s>=ha[cma[j]])
	    ok|=ans[cma[j]];
	}
	for(int j=0;j<con.size();j++){
	  ans[con[j]]=ok;
	}
      }
    }
  }
  string pr="";
  for(int i=0;i<n;i++){
    if(ans[i]) pr+='1';
    else pr+='0';
  }
  cout<<pr<<endl;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int h=1;h<dh.size();h++){
      |               ~^~~~~~~~~~
island.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int j=0;j<cma.size();j++){
      |              ~^~~~~~~~~~~
island.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int j=0;j<con.size();j++){
      |              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 31 ms 596 KB Output is correct
5 Correct 15 ms 660 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 24 ms 644 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 12 ms 708 KB Output is correct
11 Correct 18 ms 724 KB Output is correct
12 Correct 19 ms 596 KB Output is correct
13 Correct 2 ms 772 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1044 ms 22296 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1084 ms 24644 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 330 ms 17760 KB Output is correct
3 Correct 340 ms 18856 KB Output is correct
4 Correct 338 ms 16132 KB Output is correct
5 Correct 238 ms 19188 KB Output is correct
6 Correct 227 ms 17408 KB Output is correct
7 Correct 214 ms 20500 KB Output is correct
8 Correct 181 ms 26588 KB Output is correct
9 Correct 182 ms 10940 KB Output is correct
10 Correct 219 ms 17640 KB Output is correct
11 Correct 271 ms 30904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 31 ms 596 KB Output is correct
5 Correct 15 ms 660 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 24 ms 596 KB Output is correct
8 Correct 24 ms 644 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 12 ms 708 KB Output is correct
11 Correct 18 ms 724 KB Output is correct
12 Correct 19 ms 596 KB Output is correct
13 Correct 2 ms 772 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 1044 ms 22296 KB Time limit exceeded
18 Halted 0 ms 0 KB -