結果

問題 No.483 マッチ並べ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2017-04-11 18:32:31
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 2,114 bytes
コンパイル時間 1,262 ms
コンパイル使用メモリ 143,448 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-03 12:44:21
合計ジャッジ時間 3,494 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,504 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
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 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 1 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 WA -
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 WA -
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 1 ms
4,376 KB
testcase_52 WA -
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 1 ms
4,380 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];

void main() {
    int N; readf("%d\n", &N);
    auto D = new int[][](112, 112);
    auto C = new int[][](112, 112);
    foreach (i; 0 .. N) {
        int sy, sx, gy, gx;
        readf("%d %d %d %d\n", &sy, &sx, &gy, &gx);
        if (sy == gy) { // ->
            assert(gx - sx == 1);
            D[sy][sx] = 1; D[gy][gx] = 3;
        } else {
            assert(sx == gx); // v
            assert(gy - sy == 1);
            D[sy][sx] = 2; D[gy][gx] = 0;
        }
        C[sy][sx]++; C[gy][gx]++;
    }

    void dfs(int y, int x) { // (y, x)縺九i蜃コ縺ヲ縺・k霎コ縺・蛟九@縺九↑縺・↑繧峨€√◎繧後r蜀榊クー逧・↓豸亥悉
        if (C[y][x] != 1) return;
        C[y][x] = 0;
        int k = D[y][x];
        int ny = y + dy[k];
        int nx = x + dx[k];
        assert(C[ny][nx] >= 1);
        C[ny][nx]--;
        dfs(ny, nx);
    }

    foreach (int y; 0 .. 112) {
        foreach (int x; 0 .. 112) {
            dfs(y, x);
        }
    }

    int count(int y, int x) {
        int c = 0;
        if (C[y][x] % 2 == 1) {
            c++;
        }
        C[y][x] = 0;
        foreach (k; 0 .. 4) {
            int ny = y + dy[k];
            int nx = x + dx[k];
            if (ny < 0 || ny >= 112) continue;
            if (nx < 0 || nx >= 112) continue;
            if (C[ny][nx] == 0) continue;
            assert(C[ny][nx] != 1);
            c += count(ny, nx);
        }
        return c;
    }

    foreach (int y; 0 .. 112) {
        foreach (int x; 0 .. 112) {
            if (C[y][x] == 0) continue;
            assert(C[y][x] != 1);
            if (count(y, x) >= 1) {
                writeln("NO");
                return;
            }
        }
    }
    writeln("YES");

}
0