結果

問題 No.947 ABC包囲網
ユーザー ianCKianCK
提出日時 2019-12-10 18:13:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,377 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 48,976 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 02:04:27
合計ジャッジ時間 58,590 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef __int128 ll;
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("%lld%lld", &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);}
	ll operator ^(Point b) const {return x * b.y - y * b.x;}
};


const Point O(0, 0);

int dcmp(ll x) {return x > 0 ? 1 : x == 0 ? 0 : -1;}

bool segment_intersection(Point p1, Point p2, Point p3, Point p4) {
	if (debug) {
		printf("p1::"); p1.out();
		printf("p2::"); p2.out();
		printf("p3::"); p3.out();
		printf("p4::"); p4.out();
		printf("intersect? %d\n", dcmp((p2 - p1) ^ (p3 - p1)) * dcmp((p2 - p1) ^ (p4 - p1)));
		printf("intersect? %d\n", dcmp((p4 - p3) ^ (p1 - p3)) * dcmp((p4 - p3) ^ (p2 - p3)));
	}
	return dcmp((p2 - p1) ^ (p3 - p1)) * dcmp((p2 - p1) ^ (p4 - p1)) <= 0 &&
		dcmp((p4 - p3) ^ (p1 - p3)) * dcmp((p4 - p3) ^ (p2 - p3)) <= 0;
}

int n;
Point p[kN];



ll cnt(int x) {
	vector<int> left, right;
	Point now(p[x].x * kInf, p[x].y * kInf);
	int lpos = 0, rpos = 0, lsz, rsz;
	ll ans = 0, tmp;
	for (int i = 1; i <= n; i++) if (i != x) {
		tmp = p[i] ^ p[x];
		if (tmp < 0) left.PB(i);
		else if (tmp > 0) right.PB(i);
	}	

	auto cmp = [&](int a, int b) {return (p[a] ^ p[b]) > 0;};
	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 (!segment_intersection(p[left[lpos]], p[right[rpos]], now, O)) rpos++;
			else break;
		}
		if (debug) printf("lpos = %d, rpos = %d\n", lpos, rpos);
		ans += rpos;
		lpos++;
	}

	if (debug) printf("ans = %lld\n", ans);
	
	return ans;
}

int main() {
	ll 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", (long long int) ans / 3);
}
0