結果

問題 No.483 マッチ並べ
ユーザー masamasa
提出日時 2017-02-10 23:43:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,671 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 83,280 KB
実行使用メモリ 5,272 KB
最終ジャッジ日時 2023-08-28 12:28:22
合計ジャッジ時間 2,736 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>

using namespace std;

typedef struct __match {
	int x1;
	int y1;
	int x2;
	int y2;
} Match;

bool touches(Match m, int x, int y) {
	if ((m.x1 == x && m.y1 == y) || (m.x2 == x && m.y2 == y)) {
		return true;
	} else {
		return false;
	}
}

bool touches(Match a, Match b) {
	if (touches(a, b.x1, b.y1) || touches(a, b.x2, b.y2)) {
		return true;
	} else {
		return false;
	}
}

void show(vector<set<int>> vs) {
	printf("----------\n");
	for (int i = 0; i < vs.size(); i++) {
		printf("%2d: ", i);
		for (auto e : vs[i]) {
			printf("%2d ", e);
		}
		printf("\n");
	}
}

int main() {
	int n, a, b, c, d;
	cin >> n;

	vector<Match> matches(n);
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c >> d;
		Match m = {a, b, c, d};
		matches[i] = m;
	}

	vector<set<int>> connect(n);
	for (int i = 0; i < n; i++) {
		Match m1 = matches[i];
		for (int j = i + 1; j < n; j++) {
			Match m2 = matches[j];

			if (touches(m1, m2)) {
				connect[i].insert(j);
				connect[j].insert(i);
			}
		}
	}

	bool updates = true;
	do {
		updates = false;
		for (int i = 0; i < n; i++) {
			if (connect[i].size() == 1) {
				int tmp = *(connect[i].begin());
				connect[i].erase(tmp);
				connect[tmp].erase(i);
				updates = true;
			}
		}
	} while (updates);

	int maxi = 0;
	for (int i = 0; i < n; i++) {
		int next1 = 0;
		int next2 = 0;
		Match m = matches[i];
		for (auto e : connect[i]) {
			if (touches(matches[e], m.x1, m.y1)) {
				next1++;
			} else {
				next2++;
			}
		}
		maxi = max({maxi, next1, next2});
	}

	cout << (maxi > 1 ? "NO" : "YES") << endl;
	return 0;
}
0