結果

問題 No.483 マッチ並べ
ユーザー ei1333333ei1333333
提出日時 2017-02-10 22:32:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,572 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 166,372 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-28 10:31:49
合計ジャッジ時間 3,288 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 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 2 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 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,376 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 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 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,376 KB
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;


}
0