結果

問題 No.1497 Triangle
ユーザー 👑 NachiaNachia
提出日時 2022-02-16 15:19:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,728 ms / 2,000 ms
コード長 3,338 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 103,444 KB
実行使用メモリ 5,164 KB
最終ジャッジ日時 2023-09-11 17:12:47
合計ジャッジ時間 32,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 67 ms
4,380 KB
testcase_04 AC 156 ms
4,376 KB
testcase_05 AC 151 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 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,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1,728 ms
4,648 KB
testcase_23 AC 17 ms
4,380 KB
testcase_24 AC 1,006 ms
4,384 KB
testcase_25 AC 112 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 1,699 ms
4,784 KB
testcase_28 AC 957 ms
4,380 KB
testcase_29 AC 500 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 843 ms
4,376 KB
testcase_33 AC 816 ms
4,376 KB
testcase_34 AC 1,023 ms
4,380 KB
testcase_35 AC 1,127 ms
4,380 KB
testcase_36 AC 1,221 ms
4,376 KB
testcase_37 AC 1,290 ms
4,380 KB
testcase_38 AC 1,055 ms
5,164 KB
testcase_39 AC 1,003 ms
4,632 KB
testcase_40 AC 1,404 ms
5,152 KB
testcase_41 AC 1,334 ms
4,740 KB
testcase_42 AC 1,423 ms
4,380 KB
testcase_43 AC 1,453 ms
4,976 KB
testcase_44 AC 95 ms
4,380 KB
testcase_45 AC 934 ms
4,376 KB
testcase_46 AC 1,138 ms
4,564 KB
testcase_47 AC 1,266 ms
4,380 KB
testcase_48 AC 1,410 ms
4,532 KB
testcase_49 AC 1,564 ms
4,376 KB
testcase_50 AC 1,689 ms
4,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


struct Vec2{
    i64 x,y;
    Vec2 operator+(Vec2 r) const { return { x+r.x, y+r.y }; }
    Vec2 operator-() const { return { -x, -y }; }
    Vec2 operator-(Vec2 r) const { return { x-r.x, y-r.y }; }
    static i64 dot(Vec2 l, Vec2 r){ return l.x*r.x + l.y*r.y; }
    static i64 cross(Vec2 l, Vec2 r){ return l.x*r.y - l.y*r.x; }
    //      l
    //     ^
    //  +  |  -
    //   <-|->  r
};


struct ArgRange{
    Vec2 l = {0,0};
    Vec2 r = {0,0};
};


int N;
vector<Vec2> X;
vector<pair<u64, ArgRange>> argranges;


void enum_argranges(){
    map<u64, ArgRange> argranges_map;

    rep(a,N) rep(b,N) if(a != b){
        u64 mask = 0;
        rep(c,N){
            auto ab = X[b] - X[a];
            auto ac = X[c] - X[a];
            auto crossbc = Vec2::cross(ab, ac);
            auto dotbc = Vec2::dot(ab, ac);
            if(0 > crossbc) mask |= ((u64)1) << c;
            if(crossbc == 0 && 0 >= dotbc) mask |= ((u64)1) << c;
        }
        argranges_map[mask].r = X[b] - X[a];
    }

    rep(a,N) rep(b,N) if(a != b){
        u64 mask = 0;
        rep(c,N){
            auto ab = X[b] - X[a];
            auto ac = X[c] - X[a];
            auto crossbc = Vec2::cross(ab, ac);
            auto dotbc = Vec2::dot(ab, ac);
            if(0 < crossbc) mask |= ((u64)1) << c;
            if(crossbc == 0 && 0 >= dotbc) mask |= ((u64)1) << c;
        }
        argranges_map[mask].l = X[a] - X[b];
    }

    argranges.assign(argranges_map.begin(), argranges_map.end());
}


int main(){
    cin >> N;
    X.resize(N);
    rep(i,N) cin >> X[i].x >> X[i].y;
    rep(i,N) X[i] = X[i] + Vec2{ 1,1 };

    if(N == 1){ cout << "2\n"; return 0; }
    if(N == 2){ cout << "4\n"; return 0; }

    enum_argranges();
/*
    for(auto [mask, r] : argranges){
        for(int d=0; d<N; d++) cout << ((mask>>d) & 1);
        cout << " : ";
        cout << "( ( " << r.l.x << ", " << r.l.y << " ) , "
             << "( " << r.r.x << ", " << r.r.y << " ) )" << endl;
    }
*/
    set<u64> ans;
    ans.insert((((u64)1) << N) - 1);
    for(auto a : argranges) ans.insert(a.first);
    for(auto a : argranges) for(auto b : argranges) ans.insert(a.first & b.first);

    int argn = argranges.size();
    vector<int> overrange(argn, 0);
    rep(a,argn) if(Vec2::cross(argranges[a].second.l, argranges[a].second.r) < 0) overrange[a] |= 1;

    auto cancont = [](ArgRange a, ArgRange b) -> bool {
        if(Vec2::cross(a.l, b.l) > 0) return true;
        if(Vec2::cross(a.r, b.l) > 0) return true;
        if(Vec2::cross(a.l, b.r) > 0) return true;
        if(Vec2::cross(a.r, b.r) > 0) return true;
        return false;
    };

    rep(a,argn) rep(b,argn) rep(c,argn){
        auto A = argranges[a].second;
        auto B = argranges[b].second;
        auto C = argranges[c].second;
        if(!overrange[a] && !overrange[b] && !cancont(A, B)) continue;
        if(!overrange[b] && !overrange[c] && !cancont(B, C)) continue;
        if(!overrange[c] && !overrange[a] && !cancont(C, A)) continue;
        ans.insert(argranges[a].first & argranges[b].first & argranges[c].first);
    }

    cout << ans.size() << '\n';
    return 0;
}
0