結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2017-04-11 18:43:40 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,104 bytes |
| コンパイル時間 | 1,381 ms |
| コンパイル使用メモリ | 142,984 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 18:39:06 |
| 合計ジャッジ時間 | 2,682 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 WA * 10 |
ソースコード
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];
const Z = 120;
void main() {
int N; readf("%d\n", &N);
auto D = new int[][](Z, Z);
auto C = new int[][](Z, Z);
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 .. Z) {
foreach (int x; 0 .. Z) {
dfs(y, x);
}
}
bool check(int y, int x) {
int c = 0;
if (C[y][x] > 2) return false;
C[y][x] = 0;
foreach (k; 0 .. 4) {
int ny = y + dy[k];
int nx = x + dx[k];
if (ny < 0 || ny >= Z) continue;
if (nx < 0 || nx >= Z) continue;
if (C[ny][nx] == 0) continue;
assert(C[ny][nx] != 1);
if (!check(ny, nx)) return false;
}
return true;
}
foreach (int y; 0 .. Z) {
foreach (int x; 0 .. Z) {
if (C[y][x] == 0) continue;
assert(C[y][x] != 1);
if (!check(y, x)) {
writeln("NO");
return;
}
}
}
writeln("YES");
}
izuru_matsuura