結果

問題 No.340 雪の足跡
ユーザー nebukuro09nebukuro09
提出日時 2016-11-17 14:49:54
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,899 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 105,344 KB
実行使用メモリ 81,640 KB
最終ジャッジ日時 2023-09-02 22:56:59
合計ジャッジ時間 17,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 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,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 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,368 KB
testcase_11 AC 5 ms
4,372 KB
testcase_12 AC 4 ms
4,372 KB
testcase_13 AC 6 ms
4,372 KB
testcase_14 AC 72 ms
12,864 KB
testcase_15 AC 83 ms
14,712 KB
testcase_16 AC 44 ms
8,252 KB
testcase_17 AC 100 ms
13,928 KB
testcase_18 AC 92 ms
14,684 KB
testcase_19 AC 99 ms
13,928 KB
testcase_20 AC 458 ms
35,756 KB
testcase_21 AC 197 ms
7,464 KB
testcase_22 AC 8 ms
11,276 KB
testcase_23 AC 823 ms
75,512 KB
testcase_24 AC 308 ms
22,136 KB
testcase_25 AC 399 ms
28,880 KB
testcase_26 AC 64 ms
8,032 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 81 ms
10,312 KB
testcase_29 AC 903 ms
62,444 KB
testcase_30 AC 654 ms
40,872 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

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));
  bool[int][int] visited;
  auto dr = [0, 0, 1, -1];
  auto dc = [1, -1, 0, 0];
  
  while (!queue.empty) {
    auto n = queue.front;
    queue.removeFront;
    
    if (n.r == H-1 && n.c == W-1) {writeln(n.depth); return;}
    if (n.r in visited && n.c in visited[n.r]) 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 (new_r in visited && new_c in visited[new_r]) 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