結果

問題 No.199 星を描こう
ユーザー GiriGiri
提出日時 2023-06-26 01:53:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,878 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 176,576 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 16:16:24
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 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 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORE(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define trav(a, x) for (auto &a : x)

#define f first
#define s second
#define bk back()
#define pb push_back

#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)

int N, Q;

const int MX = 2e5 + 5;

using T = long long;  // or long long
const T EPS = 1e-9;   // might want to change
using P = pair<T, T>;
using vP = vector<P>;
using Line = pair<P, P>;

T sq(T a) { return a * a; }                       // square
T norm(const P &p) { return sq(p.f) + sq(p.s); }  // x^2 + y^2

// basic operations
P operator-(const P &l, const P &r) { return P(l.f - r.f, l.s - r.s); }

T cross(const P &a, const P &b) {
	return a.f * b.s - a.s * b.f;
}  // cross product

T cross(const P &p, const P &a, const P &b) {  // cross product
	return cross(a - p, b - p);
}

using vi = vector<int>;
using vP = vector<P>;

int convex_hull(const vP &v) {
    int ind = int(min_element(all(v)) - begin(v));
	vi cand, hull{ind};
	F0R(i, sz(v)) if (v[i] != v[ind]) cand.pb(i);

	sort(all(cand), [&](int a, int b) {  // sort by angle, tiebreak by distance
		P x = v[a] - v[ind], y = v[b] - v[ind];
		T t = cross(x, y);
		return t != 0 ? t > 0 : norm(x) < norm(y);
	});

	trav(c, cand) {  // for every point
		while (sz(hull) > 1 && cross(v[end(hull)[-2]], v[hull.bk], v[c]) <= 0) {
			hull.pop_back();  // pop until counterclockwise and size > 1
		}
		hull.pb(c);
	}

	return (int)hull.size();
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
    vP points(5);

    for (int i = 0; i < 5; ++i) {
        int x, y;
        cin >> x >> y;
        points[i] = P(x, y);
    }

    if (convex_hull(points) == 5) cout << "YES";
    else cout << "NO";

    return 0;
}
0