結果

問題 No.1144 Triangles
ユーザー nikkukunnikkukun
提出日時 2020-07-31 23:12:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,621 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 171,940 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 02:25:20
合計ジャッジ時間 46,545 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 246 ms
4,376 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 TLE -
testcase_23 AC 184 ms
4,376 KB
testcase_24 TLE -
testcase_25 AC 1,043 ms
4,380 KB
testcase_26 AC 98 ms
4,376 KB
testcase_27 AC 16 ms
4,376 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 21:50 - 22:02
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2000 + 5;
const int MOD = 1e9 + 7;
const int INV3 = 333333336;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

struct Point {
	ll x, y;
	Point operator+(Point rhs) {
		return (Point){(x + rhs.x) % MOD, (y + rhs.y) % MOD};
	}
	Point operator-(Point rhs) {
		return (Point){(x - rhs.x) % MOD, (y - rhs.y) % MOD};
	}
	ll operator*(Point rhs) {
		return (x * rhs.y - y * rhs.x) % MOD;
	}
};
Point p[N];

int n;

ll Solve(int rt) {
	vector<Point> pts;
	for (int i = 1; i <= n; i++)
		if (i != rt) {
			auto tmp = p[i] - p[rt];
			if (tmp.x != 0 || tmp.y != 0)
				pts.push_back(tmp);
		}
	sort(all(pts), [](Point a, Point b) {
		return atan2(a.y, a.x) < atan2(b.y, b.x);
	});

	int m = pts.size();
	for (int i = 0; i < m; i++)
		pts.push_back(pts[i]);

	Point sum = (Point){0, 0};
	ll ret = 0;
	int r = 0;
	for (int i = 0; i < m; i++) {
		while (r < i + m && pts[i] * pts[r] >= 0) {
			sum = sum + pts[r];
			r++;
		}
		ret = (ret + pts[i] * sum) % MOD;
		sum = sum - pts[i];
	}

	return ret;
}

int main() {
	ios::sync_with_stdio(0);

	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> p[i].x >> p[i].y;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ll tmp = Solve(i);
		ans = (ans + tmp) % MOD;
	}
	ans = ans * INV3 % MOD;

	cout << (ans % MOD + MOD) % MOD << endl;

	return 0;
}
0