結果
| 問題 | 
                            No.483 マッチ並べ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             izuru_matsuura
                         | 
                    
| 提出日時 | 2017-04-11 18:32:31 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,114 bytes | 
| コンパイル時間 | 1,184 ms | 
| コンパイル使用メモリ | 143,744 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-12 18:38:52 | 
| 合計ジャッジ時間 | 2,567 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 WA * 15 | 
ソースコード
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");
}
            
            
            
        
            
izuru_matsuura