結果
| 問題 |
No.947 ABC包囲網
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-10 18:06:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,302 bytes |
| コンパイル時間 | 548 ms |
| コンパイル使用メモリ | 46,932 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 01:58:06 |
| 合計ジャッジ時間 | 40,931 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 16 RE * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:93:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
93 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp: In member function ‘void Point::in()’:
main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
bool debug = false;
#include <stdio.h>
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
constexpr int kN = int(4E3 + 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;
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]], p[x], 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", ans / 3);
}