結果
| 問題 | No.635 自然門松列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-01 17:18:33 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 650 ms |
| コード長 | 2,098 bytes |
| 記録 | |
| コンパイル時間 | 1,303 ms |
| コンパイル使用メモリ | 171,268 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:17:00 |
| 合計ジャッジ時間 | 2,014 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct Pine {
int x[3];
int y[3];
};
inline int Max(int arr[]) {
return distance(arr, max_element(arr, arr + 3));
}
inline int Min(int arr[]) {
return distance(arr, min_element(arr, arr + 3));
}
inline bool Equal(double a, double b) {
return fabs(a - b) < 0.000001;
}
int main() {
int n;
cin >> n;
vector<Pine> pines;
for (int i = 0; i < n; i++) {
Pine p;
cin>> p.x[0] >> p.x[1] >> p.x[2] >> p.y[0] >> p.y[1] >> p.y[2];
pines.emplace_back(p);
}
for (Pine p : pines) {
// 真ん中が最大か最小
if (p.x[0] != p.x[1] && p.x[1] != p.x[2] && p.x[0] != p.x[2]) {
if (Max(p.x) == 1 || Min(p.x) == 1) {
cout << "YES" << endl;
continue;
}
}
// 真ん中と左右どちらかが同じ値かつ増加量も同じ
if ((p.x[0] == p.x[1] && p.y[0] == p.y[1]) || (p.x[1] == p.x[2] && p.y[1] == p.y[2]) || (p.x[0] == p.x[2] && p.y[0] == p.y[2])) {
cout << "NO" << endl;
continue;
}
// 値がすべて一致するタイミングで左右の大小が入れ替わる
double n1 = static_cast<double>(p.x[0] - p.x[1]) / (p.y[1] - p.y[0]);
double n2 = static_cast<double>(p.x[1] - p.x[2]) / (p.y[2] - p.y[1]);
if (Equal(n1, n2)) {
cout << "NO" << endl;
continue;
}
bool gt = p.x[0] > p.x[2];
// 真ん中と左右どちらかの値が同じ場合
if (p.x[0] == p.x[1] || p.x[1] == p.x[2]){
if (p.x[0] > p.x[2] && p.y[0] > p.y[2]) {
gt = true;
}
else if (p.x[0] < p.x[2] && p.y[0] < p.y[2]) {
gt = false;
}
}
else if (p.x[0] == p.x[2]) {
gt = p.y[0] < p.y[2];
}
int step = 2020;
p.x[0] += p.y[0] * step;
p.x[1] += p.y[1] * step;
p.x[2] += p.y[2] * step;
// 門松列になった
if (Max(p.x) == 1 || Min(p.x) == 1) {
cout << "YES" << endl;
continue;
}
// 左右の大小が入れ替わらなかった
if (gt == (p.x[0] > p.x[2])) {
cout << "NO" << endl;
}
// 左右の大小が入れ替わった
else {
cout << "YES" << endl;
}
}
return 0;
}