結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-11 00:18:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,837 bytes |
| コンパイル時間 | 1,527 ms |
| コンパイル使用メモリ | 96,432 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-29 11:28:10 |
| 合計ジャッジ時間 | 2,726 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 WA * 23 |
ソースコード
#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.x2);
} else {
q = make_pair(m.x1, m.y1);
}
have_match[p].erase(idx);
have_match[q].erase(idx);
updates = true;
}
} 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;
}