結果

問題 No.1497 Triangle
ユーザー 👑 tatyamtatyam
提出日時 2021-05-03 20:51:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 2,598 bytes
コンパイル時間 2,681 ms
コンパイル使用メモリ 217,432 KB
実行使用メモリ 5,140 KB
最終ジャッジ日時 2023-09-29 17:15:08
合計ジャッジ時間 6,910 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,504 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 16 ms
4,380 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 152 ms
4,808 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 85 ms
4,432 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 149 ms
5,120 KB
testcase_28 AC 87 ms
4,376 KB
testcase_29 AC 48 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 68 ms
4,384 KB
testcase_33 AC 66 ms
4,376 KB
testcase_34 AC 90 ms
4,376 KB
testcase_35 AC 99 ms
4,376 KB
testcase_36 AC 107 ms
4,376 KB
testcase_37 AC 111 ms
4,376 KB
testcase_38 AC 85 ms
5,140 KB
testcase_39 AC 85 ms
4,696 KB
testcase_40 AC 114 ms
5,044 KB
testcase_41 AC 117 ms
4,764 KB
testcase_42 AC 134 ms
4,380 KB
testcase_43 AC 119 ms
4,784 KB
testcase_44 AC 10 ms
4,380 KB
testcase_45 AC 89 ms
4,380 KB
testcase_46 AC 104 ms
4,712 KB
testcase_47 AC 116 ms
4,744 KB
testcase_48 AC 123 ms
4,744 KB
testcase_49 AC 135 ms
4,400 KB
testcase_50 AC 143 ms
4,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const double EPS = 1e-10;

P operator-(const P& a, const P& b){ return {a.first - b.first, a.second - b.second}; }
int cross(const P& a, const P& b){ return a.first * b.second - a.second * b.first; }
int dot(const P& a, const P& b){ return a.first * b.first + a.second * b.second; }
double atan(const P& a){ return atan2(a.second, a.first); }
struct Line{
    double mn = INFINITY, mx = -INFINITY;
};
int main(){
    int N;
    cin >> N;
    vector<P> A(N);
    for(auto& [x, y] : A) cin >> x >> y;
    auto cross = [&](int i, int j, int k){
        return ::cross(A[j] - A[i], A[k] - A[i]);
    };
    auto dot = [&](int i, int j, int k){
        return ::dot(A[j] - A[i], A[k] - A[i]);
    };
    auto normal = [&](int i, int j){
        return ::atan(A[j] - A[i]);
    };
    auto check = [](Line a, Line b, Line c) -> bool {
        if(a.mn > b.mn) swap(a, b);
        if(b.mn > c.mn) swap(b, c);
        if(a.mn > b.mn) swap(a, b);
        assert(c.mn - a.mn < M_PI * 2);
        if(max({a.mx, b.mx, c.mx}) - a.mn <= M_PI) return 0;
        a.mn += M_PI * 2; a.mx += M_PI * 2;
        if(max({a.mx, b.mx, c.mx}) - b.mn <= M_PI) return 0;
        b.mn += M_PI * 2; b.mx += M_PI * 2;
        if(max({a.mx, b.mx, c.mx}) - c.mn <= M_PI) return 0;
        return 1;
    };
    map<int, Line> line_;
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(i != j){
        int bit1 = 0, bit2 = 0;
        for(int k = 0; k < N; k++){
            const int c = cross(i, j, k);
            if(c > 0){
                bit1 ^= 1 << k;
                bit2 ^= 1 << k;
            }
            if(c == 0) (dot(i, j, k) > 0 ? bit1 : bit2) ^= 1 << k;
        }
        line_[bit1].mx = normal(i, j) - EPS;
        line_[bit2].mn = normal(i, j) + EPS;
    }
    vector line(line_.begin(), line_.end());
    for(auto& [bit, l] : line){
        auto& [mn, mx] = l;
        assert(mn != INFINITY && mx != -INFINITY);
        if(mn > mx) mx += M_PI * 2;
        assert(mn < mx);
        assert(mx - mn < M_PI * 2);
    }
    unordered_set<int> ans;
    ans.insert(0);
    ans.insert((1 << N) - 1);
    for(auto& [bit1, l] : line) for(auto& [bit2, l] : line){
        if(bit1 < bit2) break;
        ans.insert(bit1 & bit2);
    }
    for(auto& [bit1, l1] : line) for(auto& [bit2, l2] : line){
        if(bit1 == bit2) break;
        for(auto& [bit3, l3] : line){
            if(bit2 == bit3) break;
            if(bit1 & bit2 & bit3 && check(l1, l2, l3)) ans.insert(bit1 & bit2 & bit3);
        }
    }
    cout << ans.size() << endl;
}
0