結果
問題 |
No.483 マッチ並べ
|
ユーザー |
![]() |
提出日時 | 2017-02-10 22:32:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,572 bytes |
コンパイル時間 | 1,981 ms |
コンパイル使用メモリ | 179,688 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 08:03:24 |
合計ジャッジ時間 | 3,559 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair< int, int > Pi; const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0}; map< Pi, Pi > futon; map< Pi, int > head; bool check(const Pi &point) { head[point] = 1; head[futon[point]] = -1; bool flag = true; for(int i = 0; i < 4 && flag; i++) { const int nx = point.first + vx[i], ny = point.second + vy[i]; if(make_pair(nx, ny) == futon[point]) continue; if(head.find({nx, ny}) != head.end()) { if(head[{nx, ny}] == -1) flag = false; } else if(futon.find({nx, ny}) != futon.end()) { if(!check({nx, ny})) flag = false; } } for(int i = 0; i < 4 && flag; i++) { const int nx = futon[point].first + vx[i], ny = futon[point].second + vy[i]; if(make_pair(nx, ny) == point) continue; if(head.find({nx, ny}) != head.end()) { if(head[{nx, ny}] == 1) flag = false; } else if(futon.find({nx, ny}) != futon.end()) { if(!check(futon[{nx, ny}])) flag = false; } } return (flag); } int main() { int N, R[100]; cin >> N; vector< pair< int, int > > vv; int a[100], b[100], c[100], d[100]; for(int i = 0; i < N; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; futon[{x1, y1}] = {x2, y2}; futon[{x2, y2}] = {x1, y1}; } sort(begin(vv), end(vv)); while(!futon.empty()) { auto decide = *futon.begin(); if(head.find(decide.first) == head.end()) { if(!check(decide.first)) break; } futon.erase(futon.begin()); } if(futon.empty()) cout << "YES" << endl; else cout << "NO" << endl; }