結果

問題 No.177 制作進行の宮森あおいです!
ユーザー e-mone-mon
提出日時 2015-05-27 00:57:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 613 ms / 2,000 ms
コード長 1,948 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-20 15:26:51
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,124 KB
testcase_01 AC 18 ms
8,028 KB
testcase_02 AC 17 ms
8,004 KB
testcase_03 AC 22 ms
8,032 KB
testcase_04 AC 22 ms
8,160 KB
testcase_05 AC 43 ms
8,440 KB
testcase_06 AC 160 ms
8,768 KB
testcase_07 AC 18 ms
8,128 KB
testcase_08 AC 26 ms
8,464 KB
testcase_09 AC 405 ms
8,716 KB
testcase_10 AC 613 ms
8,708 KB
testcase_11 AC 531 ms
8,768 KB
testcase_12 AC 302 ms
8,756 KB
testcase_13 AC 17 ms
8,012 KB
testcase_14 AC 16 ms
7,996 KB
testcase_15 AC 17 ms
8,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#(to, cap, rev)
class ford_fulkerson:
    class Edge:
        def __init__(self, to, cap, rev):
            self.to = to
            self.cap = cap
            self.rev = rev

    def __init__(self,V):
        self.V = V
        self.size = [0 for i in range(V)]
        self.G = [[] for i in range(V)]

    def add_edge(self, _from, to, cap):
        self.size[_from]
        self.G[_from].append(self.Edge(to, cap, self.size[to]))
        self.G[to].append(self.Edge(_from, 0, self.size[_from]))
        self.size[_from] += 1
        self.size[to] += 1

    def dfs(self, v, t, f):
        if v == t: return f
        self.used[v] = True
        for i in range(len(self.G[v])):
            edge = self.G[v][i]
            if self.used[edge.to] is False and edge.cap > 0:
                d = self.dfs(edge.to, t, f if f < edge.cap else edge.cap)
                if d > 0:
                    self.G[v][i].cap -= d
                    self.G[edge.to][edge.rev].cap += d
                    return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.used = [False for _ in range(self.V)]
            f = self.dfs(s, t, float('inf'))
            if f == 0:
                return flow
            flow += f

W = int(input())
N = int(input())
J = list(map(int,input().split()))
M = int(input())
C = list(map(int,input().split()))

ff = ford_fulkerson(N+M+2)
for i in range(1,N+1):
    ff.add_edge(0,i,J[i-1])

for i in range(N+1,N+M+1):
    ff.add_edge(i,N+M+1,C[i-(N+1)])
    Q = list(map(int,input().split()))
    counter = 1
    for j in range(1,N+1):
        if Q[0] == 0 or Q[counter]  != j:
            ff.add_edge(j, i, 10**8) 
        elif Q[0] != 0 and Q[counter]  == j:
            ff.add_edge(j, i, 0)
            counter += 1 if counter < Q[0] else 0


if ff.max_flow(0,N+M+1) >= W:
    print('SHIROBAKO')
else:
    print('BANSAKUTSUKITA')
0