結果
問題 | No.483 マッチ並べ |
ユーザー |
![]() |
提出日時 | 2017-04-11 19:01:23 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,630 bytes |
コンパイル時間 | 1,629 ms |
コンパイル使用メモリ | 145,972 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 18:39:21 |
合計ジャッジ時間 | 2,724 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 19 |
ソースコード
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 = 5;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");}