結果
問題 | No.323 yuki国 |
ユーザー | te-sh |
提出日時 | 2017-06-27 15:45:42 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 608 ms / 5,000 ms |
コード長 | 2,897 bytes |
コンパイル時間 | 924 ms |
コンパイル使用メモリ | 128,760 KB |
実行使用メモリ | 21,296 KB |
最終ジャッジ日時 | 2024-06-12 20:32:57 |
合計ジャッジ時間 | 10,221 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 561 ms
21,236 KB |
testcase_09 | AC | 545 ms
21,184 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 551 ms
21,176 KB |
testcase_14 | AC | 594 ms
21,172 KB |
testcase_15 | AC | 480 ms
21,116 KB |
testcase_16 | AC | 566 ms
21,296 KB |
testcase_17 | AC | 551 ms
21,260 KB |
testcase_18 | AC | 10 ms
6,944 KB |
testcase_19 | AC | 367 ms
10,604 KB |
testcase_20 | AC | 22 ms
8,916 KB |
testcase_21 | AC | 608 ms
21,232 KB |
testcase_22 | AC | 168 ms
21,212 KB |
testcase_23 | AC | 605 ms
21,288 KB |
testcase_24 | AC | 59 ms
10,608 KB |
testcase_25 | AC | 544 ms
21,108 KB |
testcase_26 | AC | 54 ms
10,712 KB |
testcase_27 | AC | 607 ms
21,124 KB |
testcase_28 | AC | 592 ms
21,176 KB |
testcase_29 | AC | 591 ms
21,180 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 3 ms
6,940 KB |
testcase_33 | AC | 3 ms
6,944 KB |
testcase_34 | AC | 5 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 4 ms
6,940 KB |
testcase_37 | AC | 3 ms
6,944 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.container; // SList, DList, BinaryHeap alias Point!int point; alias Grid!(int, int) igrid; alias Grid!(bool, int) bgrid; const ml = 1101; void main() { auto rd1 = readln.split.to!(size_t[]), h = rd1[0], w = rd1[1]; auto rd2 = readln.split.to!(int[]), a = rd2[0], ps = point(rd2[2], rd2[1]); auto rd3 = readln.split.to!(int[]), b = rd3[0], pg = point(rd3[2], rd3[1]); auto m = h.iota.map!(_ => readln.chomp.map!(c => c == '*' ? 1 : -1).array).array; auto gm = igrid(m); auto gv = new bgrid[](ml); foreach (i; 0..ml) gv[i] = bgrid(h, w); struct PL { point p; int l; } auto q = DList!PL(PL(ps, a)); gv[a][ps] = true; while (!q.empty) { auto qi = q.front; q.removeFront(); auto p = qi.p, l = qi.l; foreach (np; gm.sibPoints4(p)) { auto nl = l + gm[np]; if (np == pg && nl == b) { writeln("Yes"); return; } if (nl > 0 && nl < ml && !gv[nl][np]) { gv[nl][np] = true; q.insertBack(PL(np, nl)); } } } writeln("No"); } struct Point(T) { T x, y; pure auto opBinary(string op: "+")(Point!T rhs) const { return Point!T(x + rhs.x, y + rhs.y); } pure auto opBinary(string op: "-")(Point!T rhs) const { return Point!T(x - rhs.x, y - rhs.y); } } struct Grid(T, U) { import std.algorithm, std.conv, std.range, std.traits, std.typecons; const sibs4 = [Point!U(-1, 0), Point!U(0, -1), Point!U(1, 0), Point!U(0, 1)]; const sibs8 = [Point!U(-1, 0), Point!U(-1, -1), Point!U(0, -1), Point!U(1, -1), Point!U(1, 0), Point!U(1, 1), Point!U(0, 1), Point!U(-1, 1)]; T[][] m; const size_t rows, cols; mixin Proxy!m; this(size_t r, size_t c) { rows = r; cols = c; m = new T[][](rows, cols); } this(T[][] s) { rows = s.length; cols = s[0].length; m = s; } pure auto dup() const { return Grid(m.map!(r => r.dup).array); } ref pure auto opIndex(Point!U p) { return m[p.y][p.x]; } ref pure auto opIndex(size_t y) { return m[y]; } ref pure auto opIndex(size_t y, size_t x) const { return m[y][x]; } static if (isAssignable!T) { auto opIndexAssign(T v, Point!U p) { return m[p.y][p.x] = v; } auto opIndexAssign(T v, size_t y, size_t x) { return m[y][x] = v; } auto opIndexOpAssign(string op, V)(V v, Point!U p) { return mixin("m[p.y][p.x] " ~ op ~ "= v"); } auto opIndexOpAssign(string op, V)(V v, size_t y, size_t x) { return mixin("m[y][x] " ~ op ~ "= v"); } } pure auto validPoint(Point!U p) { return p.x >= 0 && p.x < cols && p.y >= 0 && p.y < rows; } pure auto points() const { return rows.to!U.iota.map!(y => cols.to!U.iota.map!(x => Point!U(x, y))).joiner; } pure auto sibPoints4(Point!U p) { return sibs4.map!(s => p + s).filter!(p => validPoint(p)); } pure auto sibPoints8(Point!U p) { return sibs8.map!(s => p + s).filter!(p => validPoint(p)); } }