結果
問題 | No.622 点と三角柱の内外判定 |
ユーザー | tkmst201 |
提出日時 | 2021-02-18 14:45:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 4,254 bytes |
コンパイル時間 | 2,990 ms |
コンパイル使用メモリ | 202,456 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 21:15:34 |
合計ジャッジ時間 | 3,378 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// #include <cassert> #include <cmath> #include <tuple> template<typename T> struct Vec { using value_type = T; using const_reference = const value_type &; constexpr static value_type eps = 1e-8; private: value_type x, y, z; constexpr static value_type zero_limit = 1e-100; public: constexpr Vec() : x(0), y(0), z(0) {} constexpr Vec(const_reference x, const_reference y, const_reference z) : x(zero_round(x)), y(zero_round(y)), z(zero_round(z)) {} constexpr Vec operator +() const noexcept { return *this; } constexpr Vec operator -() const noexcept { return {-x, -y, -z}; } constexpr Vec & operator +=(const Vec & rhs) noexcept { x += rhs.x; y += rhs.y; z += rhs.z; return *this; } constexpr Vec & operator -=(const Vec & rhs) noexcept { x -= rhs.x; y -= rhs.y; z -= rhs.z; return *this; } constexpr Vec & operator *=(const_reference rhs) noexcept { x *= rhs; y *= rhs; z *= rhs; return *this; } constexpr Vec & operator /=(const_reference rhs) noexcept { assert(zero_round(rhs) != 0); x /= rhs; y /= rhs; z /= rhs; return *this; } friend constexpr Vec operator +(const Vec & lhs, const Vec & rhs) noexcept { return Vec(lhs) += rhs; } friend constexpr Vec operator -(const Vec & lhs, const Vec & rhs) noexcept { return Vec(lhs) -= rhs; } friend constexpr Vec operator *(const Vec & lhs, const_reference rhs) noexcept { return Vec(lhs) *= rhs; } friend constexpr Vec operator /(const Vec & lhs, const_reference rhs) noexcept { return Vec(lhs) /= rhs; } friend constexpr Vec operator *(const_reference lhs, const Vec & rhs) noexcept { return Vec(rhs) *= lhs; } friend constexpr Vec operator /(const_reference lhs, const Vec & rhs) noexcept { return Vec(rhs) /= lhs; } friend constexpr bool operator ==(const Vec & lhs, const Vec & rhs) noexcept { return !sign(lhs.x, rhs.x) && !sign(lhs.y, rhs.y) && !sign(lhs.z, rhs.z); } friend constexpr bool operator !=(const Vec & lhs, const Vec & rhs) noexcept { return !(lhs == rhs); } constexpr value_type dot(const Vec & rhs) const noexcept { return x * rhs.x + y * rhs.y + z * rhs.z; } constexpr Vec cross(const Vec & rhs) const noexcept { return {y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x}; } friend constexpr value_type dot(const Vec & lhs, const Vec & rhs) noexcept { return lhs.dot(rhs); } friend constexpr Vec cross(const Vec & lhs, const Vec & rhs) noexcept { return lhs.cross(rhs); } constexpr value_type norm2() const noexcept { return std::sqrt(square()); } constexpr value_type square() const noexcept { return dot(*this); } constexpr void normalize() noexcept { *this /= norm2(); } constexpr Vec normalized() const noexcept { return Vec(*this) /= norm2(); } std::tuple<value_type, value_type, value_type> val() const noexcept { return {x, y, z}; } const_reference getx() const noexcept { return x; } const_reference gety() const noexcept { return y; } const_reference getz() const noexcept { return z; } constexpr static value_type zero_round(const value_type & r) noexcept { return std::abs(r) < zero_limit ? 0 : r; } constexpr static int sign(const value_type & r) noexcept { return (r > eps) - (r < -eps); } constexpr static int sign(const value_type & lhs, const value_type &rhs) noexcept { return sign(lhs - rhs); } }; int main() { Vec<double> p[4]; REP(i, 4) { int x, y, z; scanf("%d %d %d", &x, &y, &z); p[i] = Vec<double>(x, y, z); } auto n = cross(p[1] - p[0], p[2] - p[0]).normalized(); const double t = dot(p[0] - p[3], n); const auto tar = p[3] + t * n; bool ans = true; REP(i, 3) { auto cur = cross(p[i] - tar, p[(i + 1) % 3] - tar).normalized(); ans &= cur == n; } puts(ans ? "YES" : "NO"); }