結果

問題 No.483 マッチ並べ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-02-10 23:48:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,746 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 153,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 12:28:51
合計ジャッジ時間 3,731 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

class strongly_connected_components{
public:
    int group_cnt; // sccの数
    vector<vector<int> > G, rG;
    vector<int> used, vs;
    vector<int> cmp; //cmp[v] := 頂点vが含まれる連結成分がどれなのかを示す番号
    strongly_connected_components(const vector<vector<int> > &g, const vector<vector<int> > &rg, int n): 
        G(g), rG(rg), cmp(2 * n), used(2 * n){
        //mainの処理
        fill(used.begin(), used.end(), 0);
        for (int i = 0; i < G.size(); ++i){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        int k = 0;
        for (int i = vs.size() - 1; i >= 0; --i){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
        group_cnt = k;
    }
    int operator[](int i){//連結成分の番号を返す
        return cmp[i];
    }
private:
    void dfs(int curr){
        used[curr] = true;
        for(auto next : G[curr]){
            if(!used[next]) dfs(next);
        }
        vs.push_back(curr);
    }
    void rdfs(int curr, int k){
        used[curr] = true;
        cmp[curr] = k;//頂点vに対して、k番目と強連結成分であること入れる
        for(auto next : rG[curr]){
            if(!used[next]) rdfs(next, k);
        }
    }
};

class twosatisfiability{
public:
    int V;
    vector<int> res; // 1:= 0:=
    vector<vector<int> > g, rg;
    twosatisfiability(int n) : V(n), g(2 * n), rg(2 * n), res(n){}

    bool exec() {
        strongly_connected_components scc(g, rg, V);
        for (int i = 0; i < V; i++) {
            if (scc[i] == scc[i + V]) return false;
            res[i] = scc[i] > scc[i + V];
        }
        return true;
    }
    void add_edge(int a, int b){
        g[a].push_back(b);
        rg[b].push_back(a);
    }
    //0~V-1: x_i
    //V~2V-1: notx_i
    void add(int a, bool apos, int b, bool bpos){//a V b をグラフへ
        add_edge(a + (apos ? V : 0), b + (bpos ? 0 : V)); // not a -> b
        add_edge(b + (bpos ? V : 0), a + (apos ? 0 : V)); // not b -> a
    }
    bool operator[](int k){
        return res[k];
    }
};

int n;
int r0[110], c0[110], r1[110], c1[110];
int main(void){
	cin >> n;
	rep(i, n){
		cin >> r0[i] >> c0[i] >> r1[i] >> c1[i];
	}
    twosatisfiability sat(n);

	rep(i, n){
        reps(j, i + 1, n){
            //そのままで一致するとき、true
            //被りが生じるような組み合わせには偽となるような節を追加
            //かぶさる可能性のあるものを反転させたものをグラフに追加する
            if (r1[i] == r1[j] && c1[i] == c1[j]){// false false
                sat.add(i, true, j, true);
            }
            if (r1[i] == r0[j] && c1[i] == c0[j]) {//false true
                sat.add(i, true, j, false);
            }
            if (r0[i] == r1[j] && c0[i] == c1[j]) {//true false
                sat.add(i, false, j, true);
            }
            if (r0[i] == r0[j] && c0[i] == c0[j]) {//true true
                sat.add(i, false, j, false);
            }
        }
    }

    bool flag = sat.exec();
    if(flag){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
	return 0;
}


0