結果

問題 No.629 グラフの中に眠る門松列
ユーザー cidercider
提出日時 2018-01-12 14:49:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 4,000 ms
コード長 1,412 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 74,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 15:33:35
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,376 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 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 21 ms
4,376 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 19 ms
4,380 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 10 ms
4,380 KB
testcase_37 AC 10 ms
4,376 KB
testcase_38 AC 13 ms
4,376 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<functional>
#define For(i, N) for (i = 0; i < N; i++)
#define rep(N) for (int i = 0; i < N; i++)
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pib = pair<int, bool>;
using pii = pair<int, int>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

int main() {
	int N, M;
	cin >> N >> M;
	int A;
	int U, V;
	int i, j;
	vector<int> a;
	vector<pii> u;
	rep(N) {
		cin >> A;
		a.push_back(A);
	}
	rep(M) {
		cin >> U >> V;
		u.push_back({ U - 1,V - 1 });
	}
	for (i = 0; i < M; i++)
		for (j = i + 1; j < M; j++) {
			int x, y, z;
			bool flag = false;
			if (u[i].first == u[j].first) {
				x = u[i].first;
				y = u[i].second;
				z = u[j].second;
				flag = true;
			}
			else if (u[i].first == u[j].second) {
				x = u[i].first;
				y = u[i].second;
				z = u[j].first;
				flag = true;
			}
			else if (u[i].second == u[j].first) {
				x = u[i].second;
				y = u[i].first;
				z = u[j].second;
				flag = true;
			}
			else if (u[i].second == u[j].second) {
				x = u[i].second;
				y = u[i].first;
				z = u[j].first;
				flag = true;
			}
			if (flag) {
				if (((a[x] < a[y] && a[x] < a[z]) || (a[x] > a[y] && a[x] > a[z])) && a[y] != a[z]) {
					say("YES");
					re;
				}
			}
		}
	say("NO");

}
0