結果

問題 No.483 マッチ並べ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2017-04-11 19:03:40
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,632 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 143,312 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 12:44:55
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

const int[] dy = [-1, 0, 1, 0];
const int[] dx = [0, 1, 0, -1];

struct Point {
    int y, x;
}
const Z = 120;

void main() {
    int N; readf("%d\n", &N);
    Point[][Point] G;
    foreach (i; 0 .. N) {
        int sy, sx, gy, gx;
        readf("%d %d %d %d\n", &sy, &sx, &gy, &gx);
        G[Point(sy, sx)] ~= Point(gy, gx);
        G[Point(gy, gx)] ~= Point(sy, sx);
    }

    bool[Point] used;
    bool dfs(in Point p, in Point prev) {
        if (p in used) {
            // 繧ゅ←縺」縺ヲ譚・縺溘i縲∵悴菴ソ逕ィ縺ョ霎コ縺梧ョ九▲縺ヲ縺・l縺ー繧「繧ヲ繝医€∵ョ九▲縺ヲ縺・↑縺代l縺ー繧サ繝シ繝・////
            foreach (next; G[p]) {
                if (next == prev) continue;
                if (next !in used) return false;
            }
            return true;
        }

        used[p] = true;
        foreach (next; G[p]) {
            if (next == prev) continue;
            if (! dfs(next, p)) return false;
        }
        return true;
    }

    foreach (int y; 0 .. Z) {
        foreach (int x; 0 .. Z) {
            if (Point(y, x) !in G) continue;
            used.clear();
            if (! dfs(Point(y, x), Point(-1, -1))) {
                writeln("NO");
                return;
            }
        }
    }
    writeln("YES");

}
0