結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,076 KB
testcase_01 AC 17 ms
7,952 KB
testcase_02 AC 17 ms
8,072 KB
testcase_03 AC 22 ms
8,180 KB
testcase_04 AC 22 ms
7,944 KB
testcase_05 AC 44 ms
8,584 KB
testcase_06 AC 168 ms
8,612 KB
testcase_07 AC 17 ms
7,952 KB
testcase_08 AC 26 ms
8,560 KB
testcase_09 AC 411 ms
8,880 KB
testcase_10 AC 637 ms
8,780 KB
testcase_11 AC 555 ms
8,728 KB
testcase_12 AC 311 ms
8,816 KB
testcase_13 AC 16 ms
8,120 KB
testcase_14 AC 17 ms
8,016 KB
testcase_15 AC 17 ms
8,168 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