結果

問題 No.483 マッチ並べ
ユーザー char134217728char134217728
提出日時 2017-08-17 08:39:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 178,152 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 14:16:54
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 5 ms
5,376 KB
testcase_49 AC 3 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   17 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ti;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

vector<ti> sat[100][2][2];
vector<pii> li[10201];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  FOR(i, 0, n){
    int a, b;
    FOR(j, 0, 2){
      cin >> a >> b;
      a = a * 101 + b;
      li[a].pb(pii(i, j));
    }
    FOR(j, 0, 2){
      FOR(k, 0, 2){
        sat[i][j][k].pb(ti(pii(i, 1-j), 1-k));
      }
    }
  }
  FOR(i, 0, 10201){
    FOR(j, 0, li[i].size()){
      int f, s;
      f = li[i][j].first;
      s = li[i][j].second;
      FOR(k, 0, li[i].size()){
        if(j==k)continue;
        int _f, _s;
        _f = li[i][k].first;
        _s = li[i][k].second;
        sat[f][s][1].pb(ti(pii(_f, _s), 0));
      }
    }
  }
  set<ti> y;
  queue<ti> q;
  ti bad, tmp;
  vector<ti> tmpv;
  FOR(i, 0, n){
    bool ok = false;
    FOR(j, 0, 2){
      bool z = false;
      y.clear();
      while(!q.empty())q.pop();
      q.push(ti(pii(i, j), 1));
      bad = ti(pii(i, j), 0);
      while(!q.empty()){
        tmp = q.front();
        q.pop();
        y.insert(tmp);
        if(tmp == bad){
          z = true;
          break;
        }
        tmpv = sat[tmp.first.first][tmp.first.second][tmp.second];
        for(vector<ti>::iterator itr = tmpv.begin(); itr != tmpv.end(); itr++){
          if(y.find(*itr) == y.end()){
            q.push(*itr);
          }
        }
      }
      if(!z)ok = true;
    }
    if(!ok){
      cout << "NO" <<endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
0