結果

問題 No.307 最近色塗る問題多くない?
ユーザー nebukuro09nebukuro09
提出日時 2016-11-03 22:00:47
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,413 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 107,084 KB
実行使用メモリ 15,588 KB
最終ジャッジ日時 2023-09-02 22:43:04
合計ジャッジ時間 7,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,736 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 3 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

int H, W;
int[][] B;
int[4] dx = [0, 0, -1, 1];
int[4] dy = [-1, 1, 0, 0];

void dfs(int srow, int scol, int color) {
  if (color == B[srow][scol])
    return;

  DList!(Tuple!(int, int)) stack;
  stack.insert(tuple(srow, scol));
  bool[int][int] visited;
  int nr, nc;

  while (!stack.empty) {
    auto node = stack.front;
    stack.removeFront();
    if (node[0] in visited && node[1] in visited[node[0]])
      continue;
    visited[node[0]][node[1]] = true;
    B[node[0]][node[1]] = color;

    foreach (i; iota(4)) {
      nr = node[0] + dx[i];
      nc = node[1] + dy[i];
      if (nr < 0 || nr >= H || nc < 0 || nc >= W)
        continue;
      if (nr in visited && nc in visited[nr])
        continue;
      if (B[nr][nc] == color)
        continue;
      stack.insert(tuple(nr, nc));
    }
  }
}

void main() {
  auto input = readln.split.map!(to!int);
  H = input[0];
  W = input[1];
  B = new int[][](H, W);
  foreach (i; iota(H))
    B[i] = readln.split.map!(to!int).array;

  int Q = readln.chomp.to!int;
  foreach (i; iota(Q)) {
    auto queries = readln.split.map!(to!int);
    dfs(queries[0]-1, queries[1]-1, queries[2]);
  }
  foreach (i; iota(H))
    writeln(B[i].map!(a => a.to!string).join(" "));
}
0