結果

問題 No.483 マッチ並べ
ユーザー masamasa
提出日時 2017-02-11 00:53:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,847 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 95,984 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 12:37:38
合計ジャッジ時間 3,043 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

typedef pair<int, int> PII;

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(map<PII, set<int>> mps) {
	printf("----------\n");
	for (auto ppp : mps) {
		PII p = ppp.first;
		printf("(%d, %d): ", p.first, p.second);
		for (auto e : ppp.second) {
			printf("%d ", 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;
	}

	map<PII, set<int>> have_match;
	for (int i = 0; i < n; i++) {
		Match m = matches[i];
		have_match[make_pair(m.x1, m.y1)].insert(i);
		have_match[make_pair(m.x2, m.y2)].insert(i);
	}


	bool updates = true;
	do {
		updates = false;
		for (auto xxx : have_match) {
			if (xxx.second.size() > 1) {
				continue;
			}
// show(have_match);
			if (xxx.second.size() == 0) {
				have_match.erase(xxx.first);
				updates = true;
				break;
			}
			PII p = xxx.first;
			int idx = *(xxx.second.begin());
			Match m = matches[idx];

			PII q;
			if (p == make_pair(m.x1, m.y1)) {
				q = make_pair(m.x2, m.y2);
			} else {
				q = make_pair(m.x1, m.y1);
			}

			have_match[p].erase(idx);
			have_match[q].erase(idx);
			updates = true;
			break;
		}
	} while (updates);

	int maxi = 0;
	for (auto x : have_match) {
		maxi = max(maxi, (int)x.second.size());
	}

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