답안 #490341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490341 2021-11-27T08:53:18 Z Wayne_Yan Roads (CEOI20_roads) C++17
30 / 100
161 ms 7876 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)

template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int maxN = 2e5+10;
pii pts[200000];

bool chk_slope(int a, int b, int c, int d){
  return (pts[b].ss - pts[a].ss) * (pts[d].ff - pts[c].ff) == (pts[d].ss - pts[c].ss) * (pts[b].ff - pts[a].ff); 
}

int dx,dy;

bool cmp(pii a, pii b){
  int va = a.ff * dy - a.ss * dx;
  int vb = b.ff * dy - b.ss * dx;
  if(va != vb) return va < vb;
  return a < b;
}

int dsu[maxN];
int query(int i){
  return (dsu[i] == i ? i : dsu[i] = query(dsu[i]));
}
void merge(int a, int b){
  if(query(a) != query(b)){
    dsu[query(a)] = query(b);
  }
}

signed main(){

  iota(dsu, dsu+maxN, 0);
  int n;
  cin >> n;
  F(2*n){
    cin >> pts[i].ff >> pts[i].ss;
  }
  bool same_slope = true;
  F(n){
    if(!chk_slope(0, 1, 2*i, 2*i+1)){
      same_slope = false;
      break;
    }
  }
  if(!same_slope){
    bool flag = true;
    F(n){
      if(pts[2*i].ff != pts[2*i+1].ff && pts[2*i].ss != pts[2*i+1].ss){
        flag = false;
        break;
      }
    }
    if(flag){
      map<pii, int> func;
      F(2*n){
        func.insert(mp(pts[i], i+1));
      }
      sort(pts, pts+2*n);
      F(n) merge(2*i+1, 2*i+2);
      F(2*n-1){
        if(query(func[pts[i]]) != query(func[pts[i+1]])){
          printf("%lld %lld %lld %lld\n", pts[i].ff, pts[i].ss, pts[i+1].ff, pts[i+1].ss);
          merge(func[pts[i]], func[pts[i+1]]);
        }
      }
    }else printf("1 3 2 1\n2 1 2 3\n2 3 3 3\n4 1 5 1\n");
  }else{
    dx = pts[0].ff - pts[1].ff;
    dy = pts[0].ss - pts[1].ss;
    sort(pts, pts + 2*n, cmp);
    F(n-1){
      printf("%lld %lld %lld %lld\n", pts[2*i+1].ff, pts[2*i+1].ss, pts[2*i+2].ff, pts[2*i+2].ss);
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Failed 43 ms 2880 KB Condition failed: "iA != P2I.end()"
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 17 ms 2436 KB Output is correct
5 Correct 33 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 16 ms 2436 KB Output is correct
5 Correct 33 ms 3008 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 2 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 17 ms 2380 KB Output is correct
10 Correct 161 ms 7876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 3 ms 1868 KB Output is correct
4 Correct 17 ms 2388 KB Output is correct
5 Correct 33 ms 2972 KB Output is correct
6 Correct 1 ms 1780 KB Output is correct
7 Failed 2 ms 1876 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 16 ms 2448 KB Output is correct
6 Correct 1 ms 1740 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 17 ms 2420 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
11 Failed 1 ms 1868 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Failed 39 ms 2812 KB Condition failed: "iA != P2I.end()"
3 Halted 0 ms 0 KB -