結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-01-24 06:25:00 | 
| 言語 | Nim  (2.2.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 535 ms / 6,000 ms | 
| コード長 | 1,092 bytes | 
| コンパイル時間 | 2,771 ms | 
| コンパイル使用メモリ | 60,784 KB | 
| 実行使用メモリ | 11,776 KB | 
| 最終ジャッジ日時 | 2024-11-08 08:10:19 | 
| 合計ジャッジ時間 | 8,142 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
ソースコード
import sequtils,deques
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord
let h = scan()
let w = scan()
var isWater : array[3001,array[3001,bool]]
for y in 0..<h:
  for x in 0..<w:
    isWater[x][y] = getchar_unlocked() == '1'
    discard getchar_unlocked()
const dxdy4 = @[(0,1),(1,0),(0,-1),(-1,0)].mapIt((x:it[0].int32,y:it[1].int32))
proc check(sx,sy:int32)  =
  var X = initDeque[int32]()
  var Y = initDeque[int32]()
  X.addLast(sx)
  Y.addLast(sy)
  while X.len() > 0:
    let x = X.popFirst()
    let y = Y.popFirst()
    for i in 0..<4:
      let nx = x+dxdy4[i].x
      let ny = y+dxdy4[i].y
      if nx < 0 or nx >= w : continue
      if ny < 0 or ny >= h : continue
      if not isWater[nx][ny] : continue
      X.addLast(nx)
      Y.addLast(ny)
      isWater[nx][ny] = false
var ans = 0
for x in 0.int32..<w.int32:
  for y in 0.int32..<h.int32:
    if not isWater[x][y]: continue
    check(x,y)
    ans += 1
echo ans