Submission #54921

# Submission time Handle Problem Language Result Execution time Memory
54921 2018-07-05T12:04:51 Z dfistric Printed Circuit Board (CEOI12_circuit) C++14
5 / 100
100 ms 8960 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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Incorrect 6 ms 488 KB Output isn't correct
3 Incorrect 9 ms 796 KB Output isn't correct
4 Correct 12 ms 796 KB Output is correct
5 Incorrect 47 ms 1152 KB Output isn't correct
6 Incorrect 35 ms 1280 KB Output isn't correct
7 Incorrect 93 ms 1720 KB Output isn't correct
8 Incorrect 28 ms 1720 KB Output isn't correct
9 Incorrect 28 ms 1720 KB Output isn't correct
10 Incorrect 42 ms 1720 KB Output isn't correct
11 Incorrect 47 ms 1720 KB Output isn't correct
12 Incorrect 59 ms 1784 KB Output isn't correct
13 Execution timed out 133 ms 2432 KB Time limit exceeded
14 Execution timed out 143 ms 3044 KB Time limit exceeded
15 Execution timed out 175 ms 3044 KB Time limit exceeded
16 Execution timed out 322 ms 5504 KB Time limit exceeded
17 Execution timed out 462 ms 6548 KB Time limit exceeded
18 Runtime error 57 ms 8124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 43 ms 8960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 44 ms 8960 KB Execution killed with signal 11 (could be triggered by violating memory limits)