結果

問題 No.947 ABC包囲網
ユーザー ianCKianCK
提出日時 2019-12-10 20:17:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,340 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 47,312 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 02:12:26
合計ジャッジ時間 47,399 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 WA -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 RE -
testcase_48 RE -
testcase_49 WA -
testcase_50 TLE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 RE -
testcase_58 WA -
testcase_59 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function ‘void Point::out()’:
main.cpp:22:28: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘ll’ {aka ‘double’} [-Wformat=]
   22 |                 printf("%lld %lld\n", x, y);
      |                         ~~~^          ~
      |                            |          |
      |                            |          ll {aka double}
      |                            long long int
      |                         %f
main.cpp:22:33: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘ll’ {aka ‘double’} [-Wformat=]
   22 |                 printf("%lld %lld\n", x, y);
      |                              ~~~^        ~
      |                                 |        |
      |                                 |        ll {aka double}
      |                                 long long int
      |                              %f
main.cpp: In function ‘int main()’:
main.cpp:95:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp: In member function ‘void Point::in()’:
main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                 scanf("%lf%lf", &x, &y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

bool debug = false;
#include <stdio.h>
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

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

struct Point {
	ll x, y;
	Point(ll a, ll b) {x = a, y = b;}
	Point() {}
	void in() {
		scanf("%lf%lf", &x, &y);
		return ;
	}
	void out() {
		printf("%lld %lld\n", x, y);
		return ;
	}
	Point operator -(Point b) const {return Point(x - b.x, y - b.y);}
	Point operator /(ll b) {return Point(x / b, y / b);}
	ll operator *(Point b) const {return x * b.x + y * b.y;}
	ll operator ^(Point b) const {return x * b.y - y * b.x;}
};

struct Line {
	ll 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(ll x) {return x > kEps ? 1 : x < -kEps ? -1 : 0;}

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);
}

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

int n;
Point p[kN];

int cnt(int x) {
	vector<int> left, right;
	int lpos = 0, rpos = 0, lsz, rsz, ans = 0;
	Line l(p[x], O);
	ll 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);
	}	

	auto cmp = [&](int a, int b) {return (p[a] ^ p[b]) > kEps;};
	sort(left.begin(), left.end(), cmp);
	sort(right.begin(), right.end(), cmp);
	
	lsz = int(left.size());
	rsz = int(right.size());
	
	if (debug) {
		printf("x = %d\n", x);
		printf("-- left --\n");
		for (int i : left) printf("%d\n", i);
		printf("-- right --\n");
		for (int i : right) printf("%d\n", i);
	}
	
	while (lpos < lsz) {
		while (rpos < rsz) {
			if (!onsegment(line_intersection(l, Line(p[left[lpos]], p[right[rpos]])), p[x], O)) rpos++;
			else break;
		}
		if (debug) printf("lpos = %d, rpos = %d\n", lpos, rpos);
		ans += rpos;
		lpos++;
	}

	if (debug) printf("ans = %d\n", ans);
	
	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);	
	assert(ans % 3 == 0);
	printf("%lld\n", ans / 3);
}
0