結果

問題 No.177 制作進行の宮森あおいです!
ユーザー e-mone-mon
提出日時 2015-05-27 00:46:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 80,116 KB
最終ジャッジ日時 2023-09-20 15:26:09
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,900 KB
testcase_01 AC 79 ms
75,272 KB
testcase_02 AC 73 ms
70,988 KB
testcase_03 AC 100 ms
76,204 KB
testcase_04 AC 107 ms
78,060 KB
testcase_05 AC 122 ms
77,656 KB
testcase_06 AC 171 ms
79,184 KB
testcase_07 AC 77 ms
74,720 KB
testcase_08 AC 107 ms
77,720 KB
testcase_09 AC 300 ms
79,384 KB
testcase_10 AC 291 ms
80,116 KB
testcase_11 AC 270 ms
79,000 KB
testcase_12 AC 211 ms
79,864 KB
testcase_13 AC 73 ms
71,136 KB
testcase_14 AC 73 ms
71,196 KB
testcase_15 AC 72 ms
71,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#(to, cap, rev)
class ford_fulkerson:
    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((to, cap, self.size[to]))
        self.G[to].append((_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])):
            to, cap, rev = self.G[v][i]
            if self.used[to] is False and cap > 0:
                d = self.dfs(to, t, f if f < cap else cap)
                if d > 0:
                    self.G[v][i] = (to, cap - d, rev)
                    self.G[to][rev] = (self.G[to][rev][0], self.G[to][rev][1] + d, self.G[to][rev][2])
                    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