結果
| 問題 |
No.1144 Triangles
|
| ユーザー |
|
| 提出日時 | 2020-07-31 23:58:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 591 ms / 3,000 ms |
| コード長 | 1,904 bytes |
| コンパイル時間 | 1,964 ms |
| コンパイル使用メモリ | 176,888 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 22:22:25 |
| 合計ジャッジ時間 | 9,822 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
// 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;
}
bool operator==(Point rhs) {
return x == rhs.x && y == rhs.y;
}
};
Point p[N];
int n;
ll Solve(int rt) {
vector<pair<double, 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(make_pair(atan2(tmp.y, tmp.x), tmp));
}
sort(all(_pts), [](pair<double, Point> &a, pair<double, Point> &b) {
return a.fi < b.fi;
});
int m = _pts.size();
vector<Point> pts;
for (int i = 0; i < m; i++)
pts.push_back(_pts[i].se);
for (int i = 0; i < m; i++)
pts.push_back(_pts[i].se);
Point sum = (Point){0, 0};
ll ret = 0, pre = 0;
int r = 0;
for (int i = 0; i < m; i++) {
if (i == 0 || !(pts[i] == pts[i - 1])) {
while (r < i + m && pts[i] * pts[r] >= 0) {
sum = sum + pts[r];
r++;
}
pre = pts[i] * sum;
}
ret = (ret + pre) % 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;
}