結果

問題 No.340 雪の足跡
ユーザー nebukuro09nebukuro09
提出日時 2016-11-17 15:32:20
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 742 ms / 1,000 ms
コード長 1,895 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 107,652 KB
実行使用メモリ 67,720 KB
最終ジャッジ日時 2023-09-02 22:57:50
合計ジャッジ時間 9,994 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 4 ms
4,368 KB
testcase_12 AC 3 ms
4,368 KB
testcase_13 AC 4 ms
4,372 KB
testcase_14 AC 36 ms
11,296 KB
testcase_15 AC 43 ms
12,076 KB
testcase_16 AC 27 ms
5,880 KB
testcase_17 AC 56 ms
14,128 KB
testcase_18 AC 48 ms
12,084 KB
testcase_19 AC 53 ms
13,928 KB
testcase_20 AC 345 ms
29,616 KB
testcase_21 AC 197 ms
7,480 KB
testcase_22 AC 9 ms
12,072 KB
testcase_23 AC 459 ms
35,476 KB
testcase_24 AC 311 ms
23,292 KB
testcase_25 AC 348 ms
26,248 KB
testcase_26 AC 58 ms
7,492 KB
testcase_27 AC 12 ms
4,372 KB
testcase_28 AC 57 ms
6,892 KB
testcase_29 AC 569 ms
52,236 KB
testcase_30 AC 373 ms
24,476 KB
testcase_31 AC 636 ms
67,720 KB
testcase_32 AC 722 ms
59,216 KB
testcase_33 AC 612 ms
59,828 KB
testcase_34 AC 742 ms
61,600 KB
testcase_35 AC 582 ms
59,496 KB
testcase_36 AC 588 ms
59,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;

void main() {
  auto input = readln.split.map!(to!int);
  auto W = input[0];
  auto H = input[1];
  auto N = input[2];
  
  auto imos_tate = new int[][](H, W);
  auto imos_yoko = new int[][](H, W);
  
  foreach (n; 0..N) {
    auto M = readln.chomp.to!int;
    auto B = readln.split.map!(to!int);
    foreach (m; 0..M) {
      
      auto r1 = min(B[m], B[m+1]) / W;
      auto c1 = min(B[m], B[m+1]) % W;
      auto r2 = max(B[m], B[m+1]) / W;
      auto c2 = max(B[m], B[m+1]) % W;
      if (r1 == r2) {
        imos_yoko[r1][c1] += 1;
        imos_yoko[r1][c2] -= 1;
      }
      else {
        imos_tate[r1][c1] += 1;
        imos_tate[r2][c1] -= 1;
      }
    }
  }

  foreach (h; 0..H)
    foreach (w; 1..W)
      imos_yoko[h][w] += imos_yoko[h][w-1];
  foreach (h; 1..H)
    foreach (w; 0..W)
      imos_tate[h][w] += imos_tate[h-1][w];

  alias Tuple!(int, "r", int, "c", int, "depth") node;
  DList!node queue;
  queue.insert(node(0, 0, 0));
  auto visited = new bool[][](H, W);
  auto dr = [0, 0, 1, -1];
  auto dc = [1, -1, 0, 0];
  
  int hoge = 0;
  while (!queue.empty) {
    auto n = queue.front;
    queue.removeFront;
    
    if (n.r == H-1 && n.c == W-1) {writeln(n.depth); return;}
    if (visited[n.r][n.c]) continue;
    visited[n.r][n.c] = true;

    foreach (i; 0..4) {
      auto new_r = n.r + dr[i];
      auto new_c = n.c + dc[i];
      if (new_r < 0 || new_r >= H || new_c < 0 || new_c >= W) continue;
      if (visited[new_r][new_c]) continue;
      if ((i <= 1 && imos_yoko[n.r][min(n.c, new_c)]) ||
          (i >= 2 && imos_tate[min(n.r, new_r)][n.c]))
        queue.insert(node(new_r, new_c, n.depth+1));
    }
  }
  writeln("Odekakedekinai..");
}
0