結果

問題 No.1430 Coup de Coupon
ユーザー tamatotamato
提出日時 2021-03-14 14:18:28
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,888 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 728,848 KB
最終ジャッジ日時 2024-11-06 04:03:06
合計ジャッジ時間 4,004 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
60,628 KB
testcase_01 AC 41 ms
53,772 KB
testcase_02 AC 41 ms
54,240 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    from heapq import heappush, heappop

    class Mincostflow():
        def __init__(self, N):
            self.N = N
            self.adj = [[] for _ in range(N + 1)]
            self.inf = 1 << 60

        def add_edge(self, fr, to, cap, cost):
            # [to, cap, cost, rev]
            forward = [to, cap, cost, None]
            backward = forward[3] = [fr, 0, -cost, forward]
            self.adj[fr].append(forward)
            self.adj[to].append(backward)

        def flow(self, s, t, f):
            N = self.N
            adj = self.adj
            inf = self.inf

            res = 0
            H = [0] * (N + 1)
            prev_v = [0] * (N + 1)
            prev_e = [None] * (N + 1)

            dist0 = [inf] * (N + 1)
            dist = [inf] * (N + 1)

            while f:
                dist[:] = dist0
                dist[s] = 0
                pq = [(0, s)]
                while pq:
                    d, v = heappop(pq)
                    if d > dist[v]:
                        continue
                    r0 = dist[v] + H[v]
                    for e in adj[v]:
                        u, cap, cost, _ = e
                        if cap > 0 and r0 + cost - H[u] < dist[u]:
                            dist[u] = r = r0 + cost - H[u]
                            heappush(pq, (r, u))
                            prev_v[u] = v
                            prev_e[u] = e

                # flow f doesn't exist
                if dist[t] == inf:
                    return None

                for i in range(1, N + 1):
                    H[i] += dist[i]

                g = f
                v = t
                while v != s:
                    g = min(g, prev_e[v][1])
                    v = prev_v[v]
                f -= g
                res += g * H[t]
                v = t
                while v != s:
                    e = prev_e[v]
                    e[1] -= g
                    e[-1][1] += g
                    v = prev_v[v]

            return res

    N, M = map(int, input().split())
    P = []
    for _ in range(N):
        P.append(int(input()))
    C = []
    for _ in range(M):
        C.append(list(map(int, input().split())))

    if M < N:
        for _ in range(N - M):
            C.append((1, 0))
        M = N

    MCF = Mincostflow(N + M + 2)
    s = N+M+1
    t = N+M+2
    for i in range(N):
        MCF.add_edge(s, i+1, 1, 0)
    for i in range(M):
        MCF.add_edge(i+N+1, t, 1, 0)
    for i in range(N):
        p = P[i]
        for j in range(M):
            flg, x = C[j]
            if flg == 1:
                p_new = max(0, p-x)
            else:
                p_new = (p // 100) * (100 - x)
            MCF.add_edge(i+1, j+N+1, 1, p_new)
    print(MCF.flow(s, t, N))


if __name__ == '__main__':
    main()
0