結果

問題 No.483 マッチ並べ
ユーザー parukiparuki
提出日時 2017-02-10 23:02:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,305 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 180,952 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-28 10:37:24
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct E {
    int to, x, y;
};
vector<E> G[101];
set<pii> fi;
vi r0, c0, r1, c1;
bool ng;
int vis[101];
void f(int u, int p) {
    vis[u]++;
    if(ng)return;
    each(e, G[u]) {
        int v = e.to, x = e.x, y = e.y, ax = -1, ay = -1;
        if(v == p)continue;
        if(vis[v])continue;
        if(mp(x, y) != mp(r0[v], c0[v]))ax = r0[v], ay = c0[v];
        else ax = r1[v], ay = c1[v];
        if(!fi.count(mp(x, y))) {
            fi.insert(mp(x, y));
            f(v, u);
        } else if(!fi.count(mp(ax,ay))) {
            fi.insert(mp(ax, ay));
            f(v, u);
        } else {
            ng = true;
            return;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    r0 = c0 = r1 = c1 = vi(N);
    vi X, Y;
    rep(i, N) {
        cin >> r0[i] >> c0[i] >> r1[i] >> c1[i];
        X.pb(r0[i]);
        Y.pb(c0[i]);
        X.pb(r1[i]);
        Y.pb(c1[i]);
    }
    rep(i, N) {
        auto p = mp(r0[i], c0[i]), q = mp(r1[i], c1[i]);
        rep(j, N) if(i!=j){
            auto r = mp(r0[j], c0[j]), s = mp(r1[j], c1[j]);
            for(auto pr : {mp(p,r),mp(p,s),mp(q,r),mp(q,s)}) {
                if(pr.first == pr.second) {
                    G[i].push_back(E{j,pr.first.first,pr.first.second});
                    break;
                }
            }
        }
    }

    rep(i, N) {
        fi.clear();
        ng = false;
        fi.insert(mp(r0[i], c0[i]));
        bool ok = false;
        f(i, -1);
        ok |= !ng;
        ng = false;
        fi.clear();
        fi.insert(mp(r1[i], c1[i]));
        f(i, -1);
        ok |= !ng;
        if(!ok) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}
0