結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-07-03 15:43:43 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,496 ms / 6,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 999 ms |
コンパイル使用メモリ | 107,136 KB |
実行使用メモリ | 132,356 KB |
最終ジャッジ日時 | 2024-06-13 01:18:26 |
合計ジャッジ時間 | 10,811 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
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); }