結果
問題 | No.947 ABC包囲網 |
ユーザー | ianCK |
提出日時 | 2019-12-10 18:06:37 |
言語 | C++11 (gcc 11.4.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 6 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 3 ms
6,940 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | WA | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | AC | 534 ms
6,944 KB |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | WA | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | WA | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | RE | - |
testcase_58 | WA | - |
testcase_59 | RE | - |
コンパイルメッセージ
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); }