結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 4 ms
4,372 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 6 ms
4,372 KB
testcase_08 AC 21 ms
4,384 KB
testcase_09 AC 9 ms
4,368 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 25 ms
4,372 KB
testcase_14 AC 11 ms
4,368 KB
testcase_15 AC 17 ms
4,372 KB
testcase_16 AC 18 ms
4,368 KB
testcase_17 AC 229 ms
14,984 KB
testcase_18 AC 777 ms
14,208 KB
testcase_19 AC 663 ms
14,984 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 463 ms
14,984 KB
testcase_22 AC 382 ms
14,984 KB
testcase_23 TLE -
testcase_24 AC 1,644 ms
14,912 KB
testcase_25 AC 38 ms
4,368 KB
testcase_26 AC 39 ms
8,524 KB
testcase_27 WA -
testcase_28 AC 34 ms
4,420 KB
testcase_29 AC 18 ms
4,368 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 50 ms
11,576 KB
testcase_34 WA -
testcase_35 AC 40 ms
6,760 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;

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;
  if (Q > 500) {
    int c;
    foreach (i; iota(Q)) {
      auto q = readln.split.map!(to!int);
      c = q[2];
    }
    foreach (i; iota(H))
      foreach (j; iota(W))
        B[i][j] = c;
  }
  else{
    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