結果
問題 | No.323 yuki国 |
ユーザー | te-sh |
提出日時 | 2017-06-27 15:44:48 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 746 ms / 5,000 ms |
コード長 | 2,898 bytes |
コンパイル時間 | 989 ms |
コンパイル使用メモリ | 129,088 KB |
実行使用メモリ | 56,872 KB |
最終ジャッジ日時 | 2024-06-12 20:32:35 |
合計ジャッジ時間 | 12,846 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 613 ms
21,224 KB |
testcase_09 | AC | 610 ms
21,188 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 571 ms
21,268 KB |
testcase_14 | AC | 625 ms
21,120 KB |
testcase_15 | AC | 581 ms
21,252 KB |
testcase_16 | AC | 609 ms
21,184 KB |
testcase_17 | AC | 479 ms
37,444 KB |
testcase_18 | AC | 213 ms
21,188 KB |
testcase_19 | AC | 416 ms
41,760 KB |
testcase_20 | AC | 429 ms
51,796 KB |
testcase_21 | AC | 724 ms
56,320 KB |
testcase_22 | AC | 416 ms
51,972 KB |
testcase_23 | AC | 746 ms
56,872 KB |
testcase_24 | AC | 586 ms
21,252 KB |
testcase_25 | AC | 587 ms
21,116 KB |
testcase_26 | AC | 637 ms
21,340 KB |
testcase_27 | AC | 640 ms
21,324 KB |
testcase_28 | AC | 601 ms
21,172 KB |
testcase_29 | AC | 602 ms
21,184 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 4 ms
6,940 KB |
testcase_33 | AC | 3 ms
6,940 KB |
testcase_34 | AC | 5 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 4 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,940 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 = SList!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.insertFront(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)); } }