結果
| 問題 |
No.947 ABC包囲網
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-10 18:12:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,379 bytes |
| コンパイル時間 | 821 ms |
| コンパイル使用メモリ | 48,580 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 02:02:06 |
| 合計ジャッジ時間 | 57,442 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 5 RE * 28 TLE * 23 |
コンパイルメッセージ
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 |
ソースコード
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);
}