답안 #134011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134011 2019-07-21T23:05:42 Z dragonslayerit Flood (IOI07_flood) C++14
13 / 100
102 ms 10636 KB
#include <cstdio>
#include <tuple>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>

const int INF=1e9+7;

struct Point{
  int x,y;
  Point():x(0),y(0){
  }
  Point(int x,int y):x(x),y(y){
  }
  void read(){
    scanf("%d %d",&x,&y);
  }
  bool operator<(Point p)const{
    return std::tie(y,x)<std::tie(p.y,p.x);
  }
  Point operator-(Point p)const{
    return Point(x-p.x,y-p.y);
  }
  double arg()const{
    return std::atan2(y,x);
  }
}ps[100005];

int elist[400005];
int head[100005];
int prev[100005];
int elist_size=0;

int next[400005];
std::vector<int> dual[100005];
int* cc=elist;
int cc_cnt=0;

int dist[100005];
int first[400005];

int q[100005];
int qh=0,qt=0;

void add(int a){
  elist[elist_size]=a;
  prev[elist_size]=head[a];
  head[a]=elist_size++;
}

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    ps[i].read();
  }
  std::fill(head,head+N,-1);
  int W;
  scanf("%d",&W);
  for(int i=0;i<W;i++){
    int A,B;
    scanf("%d %d",&A,&B);
    A--,B--;
    add(A),add(B);
  }
  for(int i=0;i<N;i++){
    std::vector<std::pair<double,int> > adj;
    for(int e=head[i];e!=-1;e=prev[e]){
      adj.push_back({(ps[elist[e]]-ps[i]).arg(),e});
    }
    std::sort(adj.begin(),adj.end());
    first[i]=adj[0].second;
    /*
    std::sort(adj[i].begin(),adj[i].end(),[i](int x,int y){
	return (ps[elist[x]]-ps[i]).arg()<
	  (ps[elist[y]]-ps[i]).arg();});
    */
    for(int j=0;j<adj.size();j++){
      int k=(j+1)%adj.size();
      next[adj[j].second]=adj[k].second^1;
    }
  }
  //elist expires
  //cc begins
  std::fill(cc,cc+W*2,-1);
  for(int i=0;i<W*2;i++){
    if(cc[i]==-1){
      for(int x=i;cc[x]==-1;x=next[x]){
	cc[x]=cc_cnt;
      }
      cc_cnt++;
    }
  }
  //printf("DUAL: %d vertices\n",cc_cnt);
  for(int i=0;i<W*2;i++){
    //printf("%d => %d: %d => %d\n",a+1,b+1,cc[i],cc[i^1]);
    dual[cc[i]].push_back(cc[i^1]);
  }
  for(int i=0;i<N;i++){
    ps[i].x=i;
  }
  std::sort(ps,ps+N);
  //std::queue<int> q;
  std::fill(dist,dist+N,INF);
  for(int i=0;i<N;i++){
    int root=cc[first[ps[i].x]^1];//cc[adj[ps[i].x][0]^1];
    if(dist[root]!=INF) continue;
    q[qh++]=root;
    dist[root]=0;
    while(qh!=qt){
      int x=q[qt++];
      for(int y:dual[x]){
	if(dist[y]==INF){
	  dist[y]=dist[x]+1;
	  q[qh++]=y;
	}
      }
    }
  }
  int survive=0;
  for(int i=0;i<W;i++){
    if(dist[cc[i*2]]==dist[cc[i*2+1]]){
      survive++;
    }
  }
  printf("%d\n",survive);
  for(int i=0;i<W;i++){
    if(dist[cc[i*2]]==dist[cc[i*2+1]]){
      printf("%d\n",i+1);
    }
  }
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:80:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<adj.size();j++){
                 ~^~~~~~~~~~~
flood.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&N);
   ~~~~~^~~~~~~~~
flood.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&W);
   ~~~~~^~~~~~~~~
flood.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&A,&B);
     ~~~~~^~~~~~~~~~~~~~~
flood.cpp: In member function 'void Point::read()':
flood.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&x,&y);
     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Incorrect 5 ms 3448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 6904 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 7672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 9548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 9616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 10424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 10636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -