結果
| 問題 |
No.1144 Triangles
|
| ユーザー |
fastmath
|
| 提出日時 | 2020-08-01 01:36:09 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,642 ms / 3,000 ms |
| コード長 | 2,572 bytes |
| コンパイル時間 | 2,847 ms |
| コンパイル使用メモリ | 164,700 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-07 00:16:36 |
| 合計ジャッジ時間 | 35,300 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
n %= MOD;
if (n < 0) return n + MOD;
else return n;
}
int fp(int a, int p) {
int ans = 1, c = a;
for (int i = 0; (1ll << i) <= p; ++i) {
if ((p >> i) & 1) ans = mod(ans * c);
c = mod(c * c);
}
return ans;
}
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
struct Point {
int x, y;
Point operator - (Point p) {
return {x - p.x, y - p.y};
}
Point operator + (Point p) {
return {x + p.x, y + p.y};
};
int operator * (Point p) {
return x * p.y - y * p.x;
}
int operator % (Point p) {
return x * p.x + y * p.y;
}
bool operator == (Point p) {
return x == p.x && y == p.y;
}
};
bool col(Point a, Point b) {
return a % b > 0 && a * b == 0;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n;
cin >> n;
vector <Point> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].x >> a[i].y;
}
int ans = 0;
for (int s = 0; s < n; ++s) {
vector <Point> v;
for (int i = 0; i < n; ++i)
if (!(a[s] == a[i]))
v.app(a[i] - a[s]);
auto comp = [] (Point a, Point b) { return atan2(a.y, a.x) < atan2(b.y, b.x); };
sort(all(v), comp);
int sz = v.size();
for (int i = 0; i < sz; ++i)
v.app(v[i]);
int j = -1; Point sum = {0, 0};
for (int i = 0; i < sz; ++i) {
if (i > j) {
assert(i == j + 1);
j = i;
sum = v[i];
}
else {
sum = sum - v[i-1];
}
while (j + 1 < i + sz && col(v[i], v[j]) && col(v[i], v[j+1])) {
++j;
sum = sum + v[j];
}
while (j + 1 < i + sz && v[i] * v[j+1] > 0) {
++j;
sum = sum + v[j];
}
ans += v[i] * sum;
ans %= MOD;
}
}
cout << dv(ans, 3) << endl;
}
fastmath