結果

問題 No.199 星を描こう
ユーザー outlineoutline
提出日時 2021-02-26 17:13:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,519 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 140,412 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:25:16
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

using ld = long double;
using Point = complex<ld>;
using Set = vector<Point>;
const ld pi = acos(-1);
constexpr ld eps = 1e-9;
constexpr ld inf = 1e12;

// 外積
ld cross(const Point& a, const Point& b){
    return a.real() * b.imag() - a.imag() * b.real();
}

// 内積
ld dot(const Point& a, const Point& b){
    return a.real() * b.real() + a.imag() * b.imag();
}

enum CCW_RESULT{
    CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0
};
// b, c に対して、a がどの位置にあるか
int ccw(Point a, Point b, Point c){
    b -= a, c -= a;
    if(cross(b, c) > eps)   return CCW;     // 上側
    if(cross(b, c) < -eps)  return CW;      // 下側
    
    // cross(b, c) == 0
    if(dot(b, c) < 0)   return BEHIND;      // 同一直線上の左側
    if(norm(b) < norm(c))   return FRONT;   // 同一直線上の右側
    return ON;      // 線分 ab 上にある
}

// 直線 (2つの点で表す)
struct Line : public vector<Point>{
    Line(const Point& a = Point(), const Point& b = Point()) : vector<Point>(2){
        begin()[0] = a;
        begin()[1] = b;
    }

    // Ax + By + C = 0
    Line(ld A, ld B, ld C){
        if(abs(A) < eps && abs(B) < eps){
            abort();
        }
        else if(abs(A) < eps){
            *this = Line(Point(0, -C / B), Point(1, -C / B));
        }
        else if(abs(B) < eps){
            *this = Line(Point(-C / A, 0), Point(-C / A, 1));
        }
        else{
            *this = Line(Point(0, -C / B), Point(-C / A, 0));
        }
    }
};

/* 交差判定 */
// 直線と直線
bool intersectLL(const Line& l, const Line& m){
    return abs(cross(l[1] - l[0], m[1] - m[0])) > eps ||    // 平行でない
           abs(cross(l[1] - l[0], m[0] - l[0])) < eps;      // 同じ直線
}
// 直線と線分
bool intersectLS(const Line &l, const Line& s){
    // cross(l[1] - l[0], s[0] - l[0]) : s[0] が左側
    // cross(l[1] - l[0], s[1] - l[0]) : s[1] が右側
    return cross(l[1] - l[0], s[0] - l[0]) * cross(l[1] - l[0], s[1] - l[0]) < eps;
}
// 直線と点
bool intersectLP(const Line& l, const Point& p){
    return abs(cross(l[1] - p, l[0] - p)) < eps;
}
// 線分と線分
bool intersectSS(const Line& s, const Line& t){
    return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
           ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
// 線分と点
bool intersectSP(const Line& s, const Point& p){
    // 三角不等式
    return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    Set ps;
    for(int i = 0; i < 5; ++i){
        int x, y;
        cin >> x >> y;
        ps.emplace_back(x, y);
    }

    vector<int> perm(5);
    for(int i = 0; i < 5; ++i)  perm[i] = i;
    do {
        bool ok = true;
        for(int i = 0; i < 5; ++i){
            //   r
            // p   q
            //  s t
            int p = perm[i], q = perm[(i + 1) % 5];
            int s = perm[(i + 2) % 5], r = perm[(i + 3) % 5], t = perm[(i + 4) % 5];
            auto x = cross(ps[q] - ps[p], ps[r] - ps[p]);
            auto y = cross(ps[q] - ps[p], ps[s] - ps[p]);
            if(x * y >= 0 || !intersectSS(Line(ps[p], ps[q]), Line(ps[r], ps[s]))){
                ok = false;
            }
            y = cross(ps[q] - ps[p], ps[t] - ps[p]);
            if(x * y >= 0 || !intersectSS(Line(ps[p], ps[q]), Line(ps[r], ps[t]))){
                ok = false;
            }
        }
        if(ok){
            cout << "YES\n";
            return 0;
        }
    } while(next_permutation(begin(perm), end(perm)));

    cout << "NO\n";

    return 0;
}
0