結果

問題 No.947 ABC包囲網
ユーザー pekempeypekempey
提出日時 2019-12-13 19:36:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 770 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 171,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 21:35:46
合計ジャッジ時間 17,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 705 ms
4,380 KB
testcase_29 AC 545 ms
4,376 KB
testcase_30 AC 770 ms
4,380 KB
testcase_31 AC 511 ms
4,376 KB
testcase_32 AC 529 ms
4,376 KB
testcase_33 AC 530 ms
4,376 KB
testcase_34 AC 515 ms
4,376 KB
testcase_35 AC 551 ms
4,380 KB
testcase_36 AC 514 ms
4,376 KB
testcase_37 AC 509 ms
4,376 KB
testcase_38 AC 521 ms
4,380 KB
testcase_39 AC 524 ms
4,380 KB
testcase_40 AC 521 ms
4,380 KB
testcase_41 AC 520 ms
4,376 KB
testcase_42 AC 524 ms
4,380 KB
testcase_43 AC 518 ms
4,380 KB
testcase_44 AC 518 ms
4,376 KB
testcase_45 AC 527 ms
4,376 KB
testcase_46 AC 501 ms
4,376 KB
testcase_47 AC 515 ms
4,380 KB
testcase_48 AC 507 ms
4,380 KB
testcase_49 AC 530 ms
4,380 KB
testcase_50 AC 496 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 4 ms
4,376 KB
testcase_58 AC 3 ms
4,380 KB
testcase_59 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

struct point {
  ll x, y;

  point(ll x_ = 0, ll y_ = 0) : x(x_), y(y_) {}

  friend point operator-(point a) {
    return point(-a.x, -a.y);
  }
  
  friend point operator-(point a, point b) {
    return point(a.x - b.x, a.y - b.y);
  }

  friend ll cross(point a, point b) {
    return a.x * b.y - a.y * b.x;
  }

  friend istream &operator>>(istream &i, point &a) {
    return i >> a.x >> a.y;
  }

  friend ostream &operator<<(ostream &o, point a) {
    return o << '(' << a.x << ',' << a.y << ')';
  }
};

int quadrant(point a) {
  if (a.x > 0 && a.y == 0) return 1;
  if (a.y > 0) return 2;
  if (a.x < 0 && a.y == 0) return 3;
  return 4;
}

bool lt(point a, point b) {
  if (quadrant(a) != quadrant(b)) return quadrant(a) < quadrant(b);
  return cross(a, b) > 0;
}

int main() {
  int N; cin >> N;
  vector<point> P(N);
  rep(i, N) cin >> P[i];
  sort(range(P), lt);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (cross(P[i], P[j]) == 0) continue;
      if (quadrant(P[i]) >= 3) continue;
      if (cross(P[j] - P[i], -P[i]) <= 0) continue;
      if (quadrant(P[j]) <= 2) {
        int l = upper_bound(P.begin() + (j + 1), P.end(), -P[i], lt) - P.begin();
        int r = lower_bound(P.begin() + (j + 1), P.end(), -P[j], lt) - P.begin();
        ans += r - l;
      } else {
        int l = upper_bound(P.begin() + (j + 1), P.end(), -P[i], lt) - P.begin();
        ans += N - l;
      }
    }
  }
  cout << ans << endl;
}
0