結果

問題 No.323 yuki国
ユーザー ikdikd
提出日時 2017-11-15 12:33:13
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 96,916 KB
実行使用メモリ 45,444 KB
最終ジャッジ日時 2023-09-03 16:55:09
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 172 ms
21,596 KB
testcase_09 AC 170 ms
21,616 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 25 ms
10,972 KB
testcase_14 AC 167 ms
21,620 KB
testcase_15 AC 164 ms
21,596 KB
testcase_16 AC 167 ms
21,572 KB
testcase_17 AC 179 ms
35,724 KB
testcase_18 AC 71 ms
15,044 KB
testcase_19 AC 139 ms
21,528 KB
testcase_20 AC 260 ms
45,444 KB
testcase_21 AC 270 ms
44,432 KB
testcase_22 AC 45 ms
14,456 KB
testcase_23 AC 265 ms
45,192 KB
testcase_24 AC 184 ms
21,596 KB
testcase_25 AC 184 ms
21,632 KB
testcase_26 AC 198 ms
21,596 KB
testcase_27 AC 200 ms
21,604 KB
testcase_28 AC 185 ms
21,616 KB
testcase_29 AC 186 ms
21,576 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.container, std.typecons;

  int h, w; rd(h, w);
  int a, si, sj; rd(a, si, sj);
  int b, gi, gj; rd(b, gi, gj);
  auto mat=new char[][](h, w);
  foreach(i; 0..h) mat[i]=readln.chomp.to!(char[]);

  alias T=Tuple!(int, "sz", int, "i", int, "j");
  auto dir=[[0, 1], [0, -1], [1, 0], [-1, 0]];
  auto vis=new bool[][][](1100, h, w);
  auto Q=new DList!(T)(T(a, si, sj));
  while(!Q.empty){
    auto cur=Q.front; Q.removeFront;
    if(cur.sz==b && cur.i==gi && cur.j==gj){writeln("Yes"); return;}
    foreach(d; dir){
      auto ni=cur.i+d[0], nj=cur.j+d[1];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      auto nsz=cur.sz+(mat[ni][nj]=='*'?1:-1);
      if(nsz>0 && nsz<1100 && !vis[nsz][ni][nj]){
        vis[nsz][ni][nj]=true;
        Q.insertFront(T(nsz, ni, nj));
      }
    }
  }

  writeln("No");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0