답안 #300884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300884 2020-09-17T14:47:36 Z Mohammad_Yasser 시간이 돈 (balkan11_timeismoney) C++17
0 / 100
1 ms 384 KB
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

const Double EPS = 1e-10;

enum Relation { LESS_THAN, EQUAL, GREATER_THAN };

bool areEqual(Double x, Double y, Double eps = EPS) {
  auto diff = abs(x - y);
  x = abs(x), y = abs(y);
  if (diff <= eps) return true;
  if (min(x, y) <= eps) return false;
  return diff <= eps * max(x, y);
}

bool isZero(Double x, Double eps = EPS) { return abs(x) <= eps; }
bool isZero(Long x) { return x == 0; }

int compareDoubles(Double x, Double y, Double eps = EPS) {
  if (areEqual(x, y, eps)) return Relation::EQUAL;
  if (x < y) return Relation::LESS_THAN;
  return Relation::GREATER_THAN;
}

template <typename T = Double>
struct Point {
  typedef Point P;
  const static P Invalid;
  const static P Origin;

  T x = 0, y = 0;
  Point(T x, T y) : x(x), y(y) {}
  Point() {}
  pair<T, T> to_pair() const { return make_pair(x, y); }
  Point operator+(const Point& p) const { return Point{x + p.x, y + p.y}; }
  Point operator-(const Point& p) const { return Point{x - p.x, y - p.y}; }
  Point operator*(T c) const { return Point(x * c, y * c); }
  Point operator/(T c) const { return Point(x / c, y / c); }
  bool operator<(const Point& p) const {
    return (*this) != p && to_pair() < p.to_pair();
  }
  bool operator>(const Point& p) const { return (*this) != p && !(*this < p); }
  bool operator==(const Point& p) const {
    return isZero(this->x - p.x) && isZero(this->y - p.y);
  }
  bool operator!=(const Point& p) const { return !(*this == p); }
  T cross(const P& p) const { return x * p.y - y * p.x; }
  T cross(const P& a, const P& b) const { return (a - *this).cross(b - *this); }
  T dot(const P& p) const { return x * p.x + y * p.y; }
  P midPoint(const P& p) const { return ((*this) + p) / 2; }
  P getVector(const P& p) const { return p - (*this); }
  T dist2(const P& p) const { return getVector(p).dist2(); }
  T dist2() const { return (*this).dot(*this); }
  Double dist(const P& p) const { return sqrt(dist2(p)); }
  Double dist() const { return sqrt(dist2()); }
  P rotateCCW90() const { return P(-y, x); }
  friend istream& operator>>(istream& is, P& p) { return is >> p.x >> p.y; }

  friend ostream& operator<<(ostream& os, const P& p) {
    return os << p.x << " " << p.y;
  }
};

template <typename T>
const Point<T> Point<T>::Invalid = Point<T>(numeric_limits<T>::max(),
                                            numeric_limits<T>::max());
template <typename T>
const Point<T> Point<T>::Origin = Point<T>(0, 0);

typedef Point<Double> P;

bool areCollinear(const P& a, const P& b, const P& c) {
  return isZero(a.getVector(b).cross(c.getVector(b)));
}

const int N = 200;

struct DSU {
  int parent[N];
  void init() {
    for (int i = 0; i < N; ++i) {
      parent[i] = i;
    }
  }
  int getRoot(int x) {
    if (parent[x] == x) return x;
    return parent[x] = getRoot(parent[x]);
  }
  bool join(int x, int y) {
    x = getRoot(x);
    y = getRoot(y);
    if (x == y) return false;
    parent[x] = y;
    return true;
  }
};

struct Edge {
  int u, v;
  Double t, c;
  bool operator<(const Edge& other) const { return t + c < other.t + other.c; }
};

vector<Edge> edges;

struct Solution {
  uint t = 0, c = 0;
  vector<pair<int, int>> edges;
  P getP() const { return P(t, c); }
  uint score() const { return t * c; }
  bool operator<(const Solution& other) const {
    return score() < other.score();
  }
  bool operator==(const Solution& other) const {
    return t == other.t && c == other.c;
  }
};

Solution mst(const P& coeff) {
  auto edges = ::edges;
  for (auto& edge : edges) {
    edge.t *= coeff.x;
    edge.c *= coeff.y;
  }
  sort(all(edges));
  static DSU dsu;
  dsu.init();
  Solution sol;
  for (auto& edge : edges) {
    if (dsu.join(edge.u, edge.v)) {
      sol.t += round(edge.t / coeff.x), sol.c += round(edge.c / coeff.y);
      sol.edges.emplace_back(edge.u, edge.v);
    }
  }
  return sol;
}
Solution best;
void solve(const P& left_v, const P& right_v, const Solution& left_sol,
           const Solution& right_sol) {
  P mid = (left_sol.getP() - right_sol.getP()).rotateCCW90();

  auto sol = mst(mid);
  best = min(best, sol);
  if (areCollinear(left_sol.getP(), sol.getP(), right_sol.getP())) return;
  solve(left_v, mid, left_sol, sol);
  solve(mid, right_v, sol, right_sol);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  P a(1, 1), b(1, 1), c(2, 2);
  cout << areCollinear(a, b, c) << endl;
  return 0;

  int n, m;
  cin >> n >> m;

  edges.resize(m);
  for (auto& edge : edges) {
    cin >> edge.u >> edge.v >> edge.t >> edge.c;
  }

  P left_v(1e-7, 1);
  P right_v(1, 1e-7);
  auto left_sol = mst(left_v);
  auto right_sol = mst(right_v);
  best = min(left_sol, right_sol);
  if (!(left_sol == right_sol)) solve(left_v, right_v, left_sol, right_sol);
  cout << best.t << " " << best.c << endl;
  for (auto [u, v] : best.edges) {
    cout << u << " " << v << endl;
  }

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
2 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
3 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
4 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
5 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
6 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
7 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
8 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
9 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
10 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
11 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
12 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
13 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
14 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
15 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
16 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected
17 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
18 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
19 Incorrect 0 ms 384 KB Unexpected end of file - int64 expected
20 Incorrect 1 ms 384 KB Unexpected end of file - int64 expected