結果

問題 No.177 制作進行の宮森あおいです!
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-05-01 23:50:47
言語 Nim
(2.0.2)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 3,311 ms
コンパイル使用メモリ 71,856 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 12:48:30
合計ジャッジ時間 5,190 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 74 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 211 ms
4,380 KB
testcase_10 AC 334 ms
4,376 KB
testcase_11 AC 283 ms
4,376 KB
testcase_12 AC 155 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

const INF: int = 1 shl 31;

type
  G = seq[seq[seq[int]]]

proc add(g: var G; u, v, cap: int) =
  g[u].add(@[v, cap, g[v].len])
  g[v].add(@[u, 0, g[u].len-1])

var visited: seq[bool]

proc dfs(g: var G, cur, sink, f: int): int =
  if cur == sink: return f
  visited[cur] = true
  for i in 0..g[cur].len-1:
    var e = g[cur][i]
    if not visited[e[0]] and e[1] > 0:
      var d = dfs(g, e[0], sink, min(f, e[1]))
      if d > 0:
        g[cur][i][1] -= d
        g[e[0]][e[2]][1] += d
        return d

proc fordFulkerson(g: var G; source, sink: int): int =
  while true:
    visited = newSeq[bool](g.len)
    var f = dfs(g, source, sink, INF)
    if f == 0: break
    result += f

when isMainModule:
  var
    w = stdin.readline.parseint
    n = stdin.readline.parseint
    js = stdin.readline.split.map(parseint)
    m = stdin.readline.parseint
    cs = stdin.readline.split.map(parseint)
    g: G = newSeqWith(n + m + 2, newSeqWith(0, newSeq[int]()))
    source = n + m
    sink = n + m + 1

  for i in 0..n-1:
    g.add(source, i, js[i])
  
  for i in n..n+m-1:
    g.add(i, sink, cs[i-n])
    var
      input = stdin.readline.split.map(parseint)
      q = input[0]
      x = input[1..input.len-1]
      pos = 0
    
    for j in 0..n-1:
      if pos < q and x[pos]-1 == j:
        g.add(j, i, 0)
        pos.inc
      else:
        g.add(j, i, INF)

  var f = fordFulkerson(g, source, sink)
  if f >= w:
    echo "SHIROBAKO"
  else:
    echo "BANSAKUTSUKITA"
    
    
0