結果

問題 No.1144 Triangles
ユーザー QCFiumQCFium
提出日時 2020-07-31 21:56:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 721 ms / 3,000 ms
コード長 1,285 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 171,996 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 23:06:26
合計ジャッジ時間 11,809 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 718 ms
4,376 KB
testcase_05 AC 721 ms
4,504 KB
testcase_06 AC 720 ms
4,380 KB
testcase_07 AC 719 ms
4,376 KB
testcase_08 AC 720 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 658 ms
4,376 KB
testcase_15 AC 652 ms
4,376 KB
testcase_16 AC 692 ms
4,380 KB
testcase_17 AC 695 ms
4,376 KB
testcase_18 AC 694 ms
4,376 KB
testcase_19 AC 38 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 668 ms
4,376 KB
testcase_23 AC 40 ms
4,376 KB
testcase_24 AC 657 ms
4,376 KB
testcase_25 AC 213 ms
4,380 KB
testcase_26 AC 23 ms
4,376 KB
testcase_27 AC 176 ms
4,376 KB
testcase_28 AC 134 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 1000000007
#define PI 3.1415926535897932384626

double my_atan2(int x, int y) {
	double res = std::atan2(y, x);
	if (res < 0) res += PI * 2;
	return res;
}

int main() {
	int n = ri();
	std::pair<int, int> pts[n];
	for (auto &i : pts) i.first = ri(), i.second = ri();
	
	struct Point {
		int x;
		int y;
		double atan2;
	};
	
	int res = 0;
	for (int i = 0; i < n; i++) {
		std::vector<Point> a;
		for (int j = 0; j < n; j++) if (i != j)
			a.push_back({pts[j].first - pts[i].first, pts[j].second - pts[i].second, 0});
		for (auto &j : a) j.atan2 = my_atan2(j.x, j.y);
		for (int j = 0; j + 1 < n; j++) a.push_back(a[j]), a.back().atan2 += 2 * PI;
		std::sort(a.begin(), a.end(), [] (auto &i, auto &j) { return i.atan2 < j.atan2; });
		int head = 0;
		int64_t r0 = 0, r1 = 0;
		int cur = 0;
		for (int j = 0; j + 1 < n; j++) {
			while (head < 2 * (n - 1) && a[head].atan2 <= a[j].atan2 + PI)
				r0 += a[head].x, r1 += a[head].y, head++;
			cur = (cur + (int64_t) r1 * a[j].x - (int64_t) r0 * a[j].y) % MOD;
			if (cur < 0) cur += MOD;
			r0 -= a[j].x;
			r1 -= a[j].y;
		}
		res += cur;
		if (res >= MOD) res -= MOD;
	}
	res = (int64_t) res * 333333336 % MOD;
	printf("%d\n", res);
	return 0;
}
0