結果

問題 No.3005 トレミーの問題
ユーザー kwm_t
提出日時 2025-01-17 22:17:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,163 bytes
コンパイル時間 7,014 ms
コンパイル使用メモリ 333,380 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-17 22:17:14
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
const double EPS = 1e-10;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
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; }
tuple<long long, long long, long long>segment(P p1, P p2) {
	long long a = p2.second - p1.second;
	long long b = p1.first - p2.first;
	long long c = p1.second * p2.first - p1.first * p2.second;
	long long g = gcd(a, gcd(b, c));
	a /= g, b /= g, c /= g;
	if (a < 0) a *= -1, b *= -1, c *= -1;
	else if (0 == a) {
		if (b < 0) b *= -1, c *= -1;
		else if (0 == b) c = abs(c);
	}
	return { a,b,c };
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<pair<int, int>>v(4);
	rep(i, 4)cin >> v[i].first >> v[i].second;
	sort(all(v));

	{
		set<tuple<long long, long long, long long>>st;
		rep(i, 4)rep2(j, i + 1, 4) {
			auto seg = segment(v[i], v[j]);
			st.insert(seg);
		}
		if (st.size() != 6) {
			cout << "NO" << endl;
			return 0;
		}
	}
	auto dist = [&](pair<int, int>s, pair<int, int>t)->double {
		int dx = s.first - t.first;
		int dy = s.second - t.second;
		return sqrt(dx*dx + dy * dy);
	};
	bool chk = false;
	do {
		double a = dist(v[3], v[0]);
		double b = dist(v[2], v[3]);
		double c = dist(v[1], v[2]);
		double d = dist(v[0], v[1]);
		double e = dist(v[0], v[2]);
		double f = dist(v[1], v[3]);
		double x = a * c + b * d;
		double y = e * f;
		if (abs(x - y) <= EPS) {
			chk = true;
		}
	} while (next_permutation(v.begin(), v.end()));
	cout << (chk ? "YES" : "NO") << endl;
	return 0;
}
0