답안 #614366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614366 2022-07-31T02:28:58 Z DanerZein 분수 공원 (IOI21_parks) C++17
5 / 100
1078 ms 116368 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int MAX_N=2e5+10;
struct point{
  int x,y,id;
  point(int xx,int yy,int ii){
    x=xx;
    y=yy;
    id=ii;
  }
  ii coord(){
    return ii(x,y);
  }
};
struct Road{
  int u,v,id;
  bool hor;
  Road(int uu,int vv,int ii,bool h){
    u=uu; v=vv; id=ii; hor=h;
  }
};
int pa[MAX_N];
int n;
vector<point> foun;
vector<Road> road;
int X[5]={0,1,0,-1};
int Y[5]={-1,0,1,0};
int ns=0;
void init(int n){
  for(int i=0;i<n;i++) pa[i]=i;
  ns=n;
}
int findset(int u){
  return pa[u]==u?u:pa[u]=findset(pa[u]);
}
bool issameset(int i,int j){
  return findset(i)==findset(j);
}
void unionset(int i,int j){
  if(!issameset(i,j)){
    int u=findset(i),v=findset(j);
    pa[u]=v;
    ns--;
  }
}
set<ii> us;
vector<ii> puntosChoque(int id){
  vector<ii> pu;
  ii f1=foun[road[id].u].coord();
  ii f2=foun[road[id].v].coord();
  int x,y;
  if(road[id].hor){
    x=(f1.first+f2.first)/2;
    y=f1.second;
  }
  else{
    x=f1.first;
    y=(f1.second+f2.second)/2;
  }
  for(int i=0;i<4;i++){
    int xk=x+X[i];
    int yk=y+Y[i];
    if(us.find(ii(xk,yk))!=us.end()) continue;
    if(ii(xk,yk)!=f1 && ii(xk,yk)!=f2)
      pu.push_back(ii(xk,yk));
  }
  return pu;
}
bool canConnect(point u,point v){
  return !issameset(u.id,v.id) && (((u.x==v.x && abs(u.y-v.y)==2)) || ((u.y==v.y && abs(u.x-v.x)==2)));
}
bool don[MAX_N];
bool sortX(point a,point b){
  return a.x!=b.x ? a.x<b.x: a.y<b.y;
}
bool sortY(point a,point b){
  return a.y!=b.y ? a.y<b.y : a.x<b.x;
}
bool origin(point a,point b){
  return a.id<b.id;
}
int be;
map<ii,int> punid;
map<int,ii> idpun;
map<int,vi> conbe;
void choque(int id){
  vector<ii> pu=puntosChoque(id);
  for(int i=0;i<pu.size();i++){
    if(punid.find(pu[i])==punid.end()){
      punid[pu[i]]=be;
      idpun[id]=pu[i];
      be++;
    }
    conbe[punid[pu[i]]].push_back(id);
  }
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
  n=x.size();
  for(int i=0;i<n;i++){
    foun.push_back(point(x[i],y[i],i));
  }
  init(n);
  sort(foun.begin(),foun.end(),sortX);
  vector<int> ua,va;
  for(int i=0;i<n-1;i++){
    if(canConnect(foun[i],foun[i+1])){
      unionset(foun[i].id,foun[i+1].id);
      ua.push_back(foun[i].id);
      va.push_back(foun[i+1].id);
      road.push_back(Road(foun[i].id,foun[i+1].id,road.size(),0));
    }
  }
  sort(foun.begin(),foun.end(),sortY);
  for(int i=0;i<n-1;i++){
    if(canConnect(foun[i],foun[i+1])){
      unionset(foun[i].id,foun[i+1].id);
      ua.push_back(foun[i].id);
      va.push_back(foun[i+1].id);  
      road.push_back(Road(foun[i].id,foun[i+1].id,road.size(),1));
    }
  }
  sort(foun.begin(),foun.end(),origin);
  if(ns!=1) return 0;
  be=road.size();
  for(int i=0;i<road.size();i++) choque(i);
  priority_queue<ii, vector<ii>, greater<ii> > pq;
  for(int i=0;i<road.size();i++){
    int pro=0;
    vector<ii> pu=puntosChoque(i);
    for(int j=0;j<pu.size();j++){
      int v=punid[pu[j]];
      pq.push(ii(conbe[v].size(),i));
    }
  }
  /*for(int i=0;i<road.size();i++){
    cout<<road[i].u<<" "<<road[i].v<<endl;
  }*/
  int t=road.size();
  vector<int> a(t),b(t);
  while(!pq.empty()){
    int i=pq.top().second;
    pq.pop();
    if(don[i]) continue;
    vector<ii> pu=puntosChoque(i);
    int iu=0;
    //cout<<i<<": \n";
    for(int j=0;j<pu.size();j++){
      int u=punid[pu[j]];
      int vis=0;
      //cout<<pu[j].first<<" "<<pu[j].second<<":\n";
      for(auto &v:conbe[u]){
	//	cout<<v<<endl;
	if(!don[v]) vis++;
      }
      if(vis==1){
	iu=j;
	break;
      }
    }
    don[i]=1;
    // cout<<endl;
    us.insert(pu[iu]);
    a[i]=pu[iu].first; b[i]=pu[iu].second;
    for(int j=0;j<pu.size();j++){
      int vis=0;
      int u=punid[pu[j]];
      int id=-1;
      for(auto &v:conbe[u]){
	if(!don[v]){
	  id=v;
	  vis++;
	}
      }
      if(vis==1){
	pq.push(ii(1,id));
      }
    }
  }
  build(ua,va,a,b);
  return 1;
}

Compilation message

parks.cpp: In function 'void choque(int)':
parks.cpp:92:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for(int i=0;i<pu.size();i++){
      |               ~^~~~~~~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:129:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Road>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |   for(int i=0;i<road.size();i++) choque(i);
      |               ~^~~~~~~~~~~~
parks.cpp:131:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Road>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |   for(int i=0;i<road.size();i++){
      |               ~^~~~~~~~~~~~
parks.cpp:134:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |     for(int j=0;j<pu.size();j++){
      |                 ~^~~~~~~~~~
parks.cpp:132:9: warning: unused variable 'pro' [-Wunused-variable]
  132 |     int pro=0;
      |         ^~~
parks.cpp:151:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |     for(int j=0;j<pu.size();j++){
      |                 ~^~~~~~~~~~
parks.cpp:168:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |     for(int j=0;j<pu.size();j++){
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1078 ms 99020 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 580 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 373 ms 39812 KB Output is correct
29 Correct 622 ms 59460 KB Output is correct
30 Correct 894 ms 79552 KB Output is correct
31 Correct 1062 ms 99080 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Incorrect 1 ms 212 KB a[0] = 2 is not an odd integer
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1078 ms 99020 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 580 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 373 ms 39812 KB Output is correct
29 Correct 622 ms 59460 KB Output is correct
30 Correct 894 ms 79552 KB Output is correct
31 Correct 1062 ms 99080 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Incorrect 1 ms 212 KB a[0] = 2 is not an odd integer
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
17 Incorrect 1 ms 212 KB a[0] = 199998 is not an odd integer
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
17 Correct 1072 ms 116076 KB Output is correct
18 Correct 1024 ms 116368 KB Output is correct
19 Correct 952 ms 75232 KB Output is correct
20 Correct 1062 ms 86360 KB Output is correct
21 Correct 1016 ms 93124 KB Output is correct
22 Incorrect 0 ms 212 KB a[1] = 183568 is not an odd integer
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 511 ms 58816 KB Output is correct
10 Correct 34 ms 6164 KB Output is correct
11 Correct 230 ms 31848 KB Output is correct
12 Correct 57 ms 8992 KB Output is correct
13 Correct 16 ms 3980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 474 ms 58784 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1078 ms 99020 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 580 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 373 ms 39812 KB Output is correct
29 Correct 622 ms 59460 KB Output is correct
30 Correct 894 ms 79552 KB Output is correct
31 Correct 1062 ms 99080 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Incorrect 1 ms 212 KB a[0] = 2 is not an odd integer
34 Halted 0 ms 0 KB -