結果

問題 No.947 ABC包囲網
ユーザー ianCKianCK
提出日時 2020-09-26 17:15:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,848 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 60,668 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-11 21:18:37
合計ジャッジ時間 13,289 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 6 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 7 ms
4,384 KB
testcase_20 AC 6 ms
4,384 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 6 ms
4,384 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 6 ms
4,384 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 1,559 ms
4,380 KB
testcase_29 AC 1,845 ms
4,384 KB
testcase_30 AC 578 ms
4,380 KB
testcase_31 AC 1,844 ms
4,384 KB
testcase_32 AC 1,835 ms
4,384 KB
testcase_33 AC 1,835 ms
4,384 KB
testcase_34 AC 1,837 ms
4,380 KB
testcase_35 AC 1,836 ms
4,384 KB
testcase_36 AC 1,843 ms
4,384 KB
testcase_37 AC 1,843 ms
4,380 KB
testcase_38 AC 1,844 ms
4,380 KB
testcase_39 AC 1,840 ms
4,388 KB
testcase_40 AC 1,839 ms
4,380 KB
testcase_41 AC 1,837 ms
4,380 KB
testcase_42 AC 1,835 ms
4,384 KB
testcase_43 AC 1,848 ms
4,384 KB
testcase_44 AC 1,835 ms
4,384 KB
testcase_45 AC 1,839 ms
4,384 KB
testcase_46 AC 1,836 ms
4,384 KB
testcase_47 AC 1,847 ms
4,384 KB
testcase_48 AC 1,842 ms
4,384 KB
testcase_49 AC 1,843 ms
4,384 KB
testcase_50 AC 1,840 ms
4,388 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 3 ms
4,384 KB
testcase_53 AC 2 ms
4,384 KB
testcase_54 AC 2 ms
4,388 KB
testcase_55 AC 2 ms
4,384 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 7 ms
4,380 KB
testcase_58 AC 7 ms
4,508 KB
testcase_59 AC 7 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

constexpr double kEps = 1E-10;
constexpr int kN = int(4E3 + 10); 
#define PB push_back

struct Point {
	double x, y;
	Point(double a, double b) {x = a, y = b;}
	Point() {}
	void in() {
		scanf("%lf%lf", &x, &y);
		return ;
	}
	inline Point operator -(Point b) const {return Point(x - b.x, y - b.y);}
	inline Point operator /(double b) const {return Point(x / b, y / b);}
	inline double operator *(Point b) const {return x * b.x + y * b.y;}
	inline double operator ^(Point b) const {return x * b.y - y * b.x;}
};

struct Line {
	double a, b, c;
	Line(Point pa, Point pb) :a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb){}
};


const Point O(0, 0);

int dcmp(double x) {return x > kEps ? 1 : x < -kEps ? -1 : 0;}

inline Point line_intersection(Line l1, Line l2) {
	return Point(-l1.b * l2.c + l1.c * l2.b, l1.a * l2.c - l1.c * l2.a) / (-l1.a * l2.b + l1.b * l2.a);
}

inline bool onsegment(Point p, Point a, Point b) {
	return dcmp((a - p) * (b - p)) < -kEps;
}

int n;
Point p[kN];
bool cmp(int a, int b) {return (p[a] ^ p[b]) > kEps;}

int cnt(int x) {
	vector<int> left, right;
	int lpos = 0, rpos = 0, lsz, rsz, ans = 0;
	Line l(p[x], O);
	double tmp;
	for (int i = 1; i <= n; i++) if (i != x) {
		tmp = p[i] ^ p[x];
		if (tmp < -kEps) left.PB(i);
		else if (tmp > kEps) right.PB(i);
	}	

	sort(left.begin(), left.end(), cmp);
	sort(right.begin(), right.end(), cmp);
	
	lsz = int(left.size());
	rsz = int(right.size());
	
	while (lpos < lsz) {
		while (rpos < rsz) {
			if (onsegment(O, line_intersection(l, Line(p[left[lpos]], p[right[rpos]])), p[x])) rpos++;
			else break;
		}
		ans += rpos;
		lpos++;
	}
	
	return ans;
}

int main() {
	long long int ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) p[i].in();

	for (int i = 1; i <= n; i++) ans += cnt(i);	
	printf("%lld\n", ans / 3);
}
0