답안 #54922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54922 2018-07-05T12:05:36 Z dfistric Printed Circuit Board (CEOI12_circuit) C++14
10 / 100
100 ms 9096 KB
#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define point pair <ld, ld>
#define X first
#define Y second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 100010;

struct line {
  point A, B;
};

line lines[MAXN];
point ray;
set <line> s;
vector <point> ve;
vector <int> out;
int arr[MAXN];
int n;
const ld eps = 1e-8;

int ccw(point a, point b, point c) {
  ld out = ((ld) a.X * (b.Y - c.Y)) +
           ((ld) b.X * (c.Y - a.Y)) +
           ((ld) c.X * (a.Y - b.Y));
  if (out > 0.0) return  1;
  if (out < 0.0) return -1;
  return 0;
}

int ccw0(point a, point b) {
  return ccw({0, 0}, a, b);
}

ld dist(point a) {
  return (a.X * a.X) + (a.Y * a.Y);
}

point inter(line a, line b) {
  ld ka = (a.A.Y - a.B.Y) / (a.A.X - a.B.X + eps);
  ld kb = (b.A.Y - b.B.Y) / (b.A.X - b.B.X + eps);
  ld la = a.A.Y - a.A.X * ka;
  ld lb = b.A.Y - b.A.X * kb;

  if (fabs(ka - kb) <= eps && fabs(la - lb) <= eps) {
    if (dist(a.A) < dist(a.B)) return a.A;
    return a.B;
  }

  ld x = (lb - la) / (ka - kb + eps);

  return {x, ka * x + la};
}

bool operator< (const line &x, const line &y) {
  point a = x.A, b = x.B;
  point c = y.A, d = y.B;

  if (ccw0(a, b) < 0) swap(a, b);
  if (ccw0(c, d) < 0) swap(c, d);

  if (ccw(a, b, c) <= 0 && ccw(a, b, d) <= 0) return 1;
  if (ccw(a, b, c) >= 0 && ccw(a, b, d) >= 0) return 0;

  point ix = inter({a, b}, {{0, 0}, ray});
  point iy = inter({c, d}, {{0, 0}, ray});

  ld dx = dist(ix);
  ld dy = dist(iy);

  return dx < dy;
}

bool cmp(int aa, int bb) {
  point a = ve[aa];
  point b = ve[bb];

  if (ccw0(a, b) == 0) {
    ld da = dist(a);
    ld db = dist(b);

    return da < db;
  }
  return ccw0(a, b) > 0;
}

int main() {
  ios_base::sync_with_stdio(false);

  /*line a;
  a.A = {100, 20};
  a.B = {12, 50};
  line b;
  b.A = {100, 20};
  b.B = {150, 10};

  cout << (a < b) << endl;
  cout << (b < a) << endl;*/

  cin >> n;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    ve.push_back({a, b});
    arr[i] = i;
  }

  sort(arr, arr + n, cmp);

  REP(ind, n) {
    int i = arr[ind];
    point x = ve[i];
    ray = x;

    for (int t : {-1, 1}) {
      int j = (i + t + n) % n;
      point y = ve[j];

      if (cmp(i, j)) {
        line tr = {x, y};
        s.insert(tr);
      }
    }

    ld dx = dist(x), dy = 1e13;
    if (s.size()) {
      line tr = *s.begin();
      point y = inter(tr, {{0, 0}, ray});
      dy = dist(y);
    }

    if (dx - dy <= 0.0001) {
      out.push_back(i);
    }

    for (int t : {-1, 1}) {
      int j = (i + t + n) % n;
      point y = ve[j];

      if (!cmp(i, j)) {
        line tr = {y, x};
        s.erase(tr);
      }
    }
  }

  sort(out.begin(), out.end());
  cout << out.size() << "\n";
  for (int x : out) cout << x + 1 << " ";
  cout << "\n";

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 5 ms 572 KB Output isn't correct
3 Correct 8 ms 800 KB Output is correct
4 Correct 10 ms 1056 KB Output is correct
5 Incorrect 25 ms 1072 KB Output isn't correct
6 Incorrect 25 ms 1116 KB Output isn't correct
7 Incorrect 51 ms 1872 KB Output isn't correct
8 Incorrect 21 ms 1872 KB Output isn't correct
9 Incorrect 24 ms 1992 KB Output isn't correct
10 Incorrect 27 ms 1992 KB Output isn't correct
11 Incorrect 28 ms 1992 KB Output isn't correct
12 Incorrect 52 ms 1992 KB Output isn't correct
13 Incorrect 87 ms 2792 KB Output isn't correct
14 Incorrect 98 ms 5236 KB Output isn't correct
15 Execution timed out 129 ms 5236 KB Time limit exceeded
16 Execution timed out 275 ms 5236 KB Time limit exceeded
17 Execution timed out 358 ms 6988 KB Time limit exceeded
18 Runtime error 45 ms 8196 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 34 ms 8912 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 40 ms 9096 KB Execution killed with signal 11 (could be triggered by violating memory limits)