結果

問題 No.421 しろくろチョコレート
ユーザー むらためむらため
提出日時 2019-01-31 06:54:51
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 2,023 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 67,356 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-14 03:19:38
合計ジャッジ時間 5,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 3 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 3 ms
4,992 KB
testcase_29 AC 5 ms
5,088 KB
testcase_30 AC 4 ms
5,056 KB
testcase_31 AC 10 ms
6,480 KB
testcase_32 AC 5 ms
5,552 KB
testcase_33 WA -
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 6 ms
4,844 KB
testcase_45 WA -
testcase_46 AC 2 ms
4,376 KB
testcase_47 WA -
testcase_48 AC 7 ms
5,112 KB
testcase_49 AC 3 ms
4,388 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 5 ms
4,552 KB
testcase_52 WA -
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 1 ms
4,376 KB
testcase_64 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

# 最大流 O(FE) (F:最大流の流量)
type Edge = tuple[dst,cap,rev:int]
const INF = 1e10.int
type Flow = seq[seq[Edge]]
proc add(F:var Flow,src,dst,cap:int) =
  F[src] &= (dst,cap,F[dst].len)
  F[dst] &= (src,0,F[src].len - 1)
proc fordFullkerson(F:var Flow,src,dst:int) : int =
  var used : seq[bool]
  proc dfs(F:var Flow,src,dst,flow:int) : int =
    if src == dst : return flow
    used[src] = true
    for i,e in F[src]:
      if used[e.dst] or e.cap <= 0 : continue
      let d = F.dfs(e.dst,dst,flow.min(e.cap))
      if d <= 0 : continue
      F[src][i].cap -= d
      F[e.dst][e.rev].cap += d
      return d
  while true:
    used = newSeq[bool](F.len)
    let flow = F.dfs(src,dst,INF)
    if flow == 0 : return
    result += flow


proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

let h = scan()
let w = scan()
proc encode(x,y:int):int = x * h + y
let n = h * w
var C = newSeqWith(w,newSeqWith(h,'.'))
for y in 0..<h:
  for x in 0..<w:
    C[x][y] = getchar_unlocked()
  discard getchar_unlocked()
var F : Flow = newSeqWith(n+2,newSeq[Edge]())
var wSum = 0
var bSum = 0
for x in 0..<w:
  for y in 0..<h:
    if C[x][y] == '.' : continue
    const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]
    if C[x][y] == 'w' :
      F.add(encode(x,y),n,1)
      wSum += 1
    else :
      F.add(n+1,encode(x,y),1)
      bSum += 1
    for d in dxdy4:
      let nx = x + d.x
      let ny = y + d.y
      if nx < 0 or ny < 0 or nx >= w or ny >= h : continue
      if C[nx][ny] == '.' : continue
      F.add(encode(x,y),encode(nx,ny),1)
var ans = F.fordFullkerson(n+1,n)
wSum -= ans
bSum -= ans
ans *= 100
let pair = min(bSum,wSum)
ans = ans + 10 * pair
wSum -= pair
bSum -= pair
echo ans + wSum + bSum
0