답안 #55000

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

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

using namespace std;

const ll MAXN = 200010;

struct line {
  poll A, B;
};

line lines[MAXN];
poll ray;
multiset <line> s;
vector <poll> ve;
vector <ll> out;
ll arr[MAXN];
int n;

ll ccw(poll a, poll b, poll c) {
  ll out = ((ll) a.X * (b.Y - c.Y)) +
           ((ll) b.X * (c.Y - a.Y)) +
           ((ll) c.X * (a.Y - b.Y));
  return out;
}

ll ccw0(poll a, poll b) {
  return ccw({0, 0}, a, b);
}

ll dist(poll a) {
  return (a.X * a.X) + (a.Y * a.Y);
}

bool operator==(line x, line y) {
  return x.A == y.A && x.B == y.B;
}

bool operator< (line x, line y) {
  if (x == y) return 0;
  if (ccw0(x.A, x.B) < 0) swap(x.A, x.B);
  if (ccw0(y.A, y.B) < 0) swap(y.A, y.B);

  ll P = ccw(x.B, x.A, y.A) + ccw(x.B, y.A, y.B);

  if (P == 0) {
    if (x.A.Y == y.A.Y) return x.A.X < y.A.X;
    return x.A.Y < y.A.Y;
  }

  return P > 0;
}

bool cmp(ll a, ll b) {
  if (ccw0(ve[a], ve[b]) == 0) {
    return ve[a] < ve[b];
  }
  return ccw0(ve[a], ve[b]) > 0;
}

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

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

  sort(arr, arr + n, cmp);

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

    for (ll t : {-1, 1}) {
      ll j = (i + t + n) % n;
      poll y = ve[j];
      
      if (cmp(i, j)) {
        line tr = {x, y};
        s.insert(tr);
      }
    }

    if (ind == 0 || ccw0(ve[i], ve[arr[ind - 1]]) != 0) {
      line tr = *s.begin();
      if (ccw(tr.A, tr.B, x) == 0) out.push_back(i);
    }

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

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

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

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 6 ms 572 KB Output is correct
4 Correct 7 ms 800 KB Output is correct
5 Correct 16 ms 880 KB Output is correct
6 Correct 14 ms 952 KB Output is correct
7 Correct 30 ms 1456 KB Output is correct
8 Correct 10 ms 1456 KB Output is correct
9 Correct 10 ms 1456 KB Output is correct
10 Correct 19 ms 1456 KB Output is correct
11 Correct 13 ms 1456 KB Output is correct
12 Correct 16 ms 1456 KB Output is correct
13 Correct 38 ms 1732 KB Output is correct
14 Correct 36 ms 1988 KB Output is correct
15 Correct 40 ms 2028 KB Output is correct
16 Correct 95 ms 3308 KB Output is correct
17 Execution timed out 214 ms 4580 KB Time limit exceeded
18 Execution timed out 190 ms 6108 KB Time limit exceeded
19 Execution timed out 181 ms 6860 KB Time limit exceeded
20 Execution timed out 331 ms 10912 KB Time limit exceeded