結果

問題 No.697 池の数はいくつか
ユーザー むらためむらため
提出日時 2019-01-24 06:25:00
言語 Nim
(2.0.2)
結果
AC  
実行時間 439 ms / 6,000 ms
コード長 1,092 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 61,556 KB
実行使用メモリ 11,908 KB
最終ジャッジ日時 2024-04-25 20:22:54
合計ジャッジ時間 7,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 47 ms
7,652 KB
testcase_25 AC 47 ms
7,384 KB
testcase_26 AC 48 ms
6,940 KB
testcase_27 AC 45 ms
6,940 KB
testcase_28 AC 45 ms
6,960 KB
testcase_29 AC 437 ms
11,692 KB
testcase_30 AC 414 ms
11,664 KB
testcase_31 AC 439 ms
11,796 KB
testcase_32 AC 427 ms
11,908 KB
testcase_33 AC 412 ms
11,604 KB
testcase_34 AC 432 ms
11,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0