結果

問題 No.697 池の数はいくつか
ユーザー te-shte-sh
提出日時 2018-07-03 15:43:43
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,420 ms / 6,000 ms
コード長 1,021 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 95,412 KB
実行使用メモリ 131,868 KB
最終ジャッジ日時 2023-09-03 20:30:42
合計ジャッジ時間 10,923 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 115 ms
6,452 KB
testcase_25 AC 109 ms
6,668 KB
testcase_26 AC 108 ms
5,900 KB
testcase_27 AC 108 ms
6,676 KB
testcase_28 AC 110 ms
5,864 KB
testcase_29 AC 1,420 ms
131,864 KB
testcase_30 AC 969 ms
7,764 KB
testcase_31 AC 1,404 ms
131,868 KB
testcase_32 AC 948 ms
7,748 KB
testcase_33 AC 953 ms
7,732 KB
testcase_34 AC 961 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.bitmanip;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int h, w; readV(h, w);
  auto n = (h+2)*(w+2);

  auto b = BitArray();
  b.length = n;

  foreach (r; 0..h) {
    int[] a; readA(w, a);
    foreach (c; 0..w)
      if (a[c]) b[(r+1)*(w+2)+c+1] = true;
  }

  auto v = BitArray();
  v.length = n;

  auto p = 0;
  foreach (i; 0..n) {
    if (b[i] && !v[i]) {
      ++p;
      auto q = DList!int(i);
      v[i] = true;
      while (!q.empty) {
        auto d = q.front; q.removeFront();
        foreach (e; [d-1, d+1, d-(w+2), d+(w+2)]) {
          if (b[e] && !v[e]) {
            v[e] = true;
            q.insertBack(e);
          }
        }
      }
    }
  }

  writeln(p);
}
0