結果

問題 No.2422 regisys?
ユーザー FromBooska
提出日時 2023-08-19 16:51:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
MLE  
実行時間 -
コード長 2,219 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 818,004 KB
最終ジャッジ日時 2024-11-29 10:54:37
合計ジャッジ時間 57,379 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31 TLE * 2 MLE * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

# マッチング、最大流でできるか、間に合うか
# Start, M人M頂点、N商品N頂点、Goal

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
TC = []
for i in range(M):
    t, c = map(int, input().split())
    TC.append((t, c))

Start = 0
Goal = M+N+1
from collections import defaultdict, deque
INF = float('inf')
edges = defaultdict(set)
cost = [[0]*(M+N+2) for i in range(M+N+2)]
for i in range(M):
    t, c = TC[i]
    for j in range(N):
        a = A[j]
        b = B[j]
        if (t == 0 and a <= c) or (t == 1 and b <= c):
            edges[i+1].add(j+M+1)
            cost[i+1][j+M+1] = 1

# from Start to M nodes
for i in range(M):
    edges[Start].add(i+1)
    cost[Start][i+1] = 1
    
# from N nodes to Goal
for i in range(N):
    edges[i+M+1].add(Goal)
    cost[i+M+1][Goal] = 1   

ans = 0
def Ford_Fulkerson(s): #sからFord-Fulkerson
    global edges
    global cost
    global ans
    queue = deque()     #BFS用のdeque
    queue.append([s,INF])
    ed = [True]*(M+N+2+1)    #到達済み
    ed[s] = False
    route = [0 for i in range(M+N+2+1)]   #ルート
    route[s] = -1
    #BFS
    while queue:
        s,flow = queue.pop()
        for t in edges[s]:  #s->t
            if ed[t]:
                flow = min(cost[s][t],flow)  #flow = min(直前のflow,line容量)
                route[t] = s
                queue.append([t,flow])
                ed[t] = False
                if t == Goal: #ゴール到達
                    ans += flow
                    break
        else:
            continue
        break
    else:
        return False
    #ラインの更新
    t = Goal
    s = route[t]
    while s != -1:
        #s->tのコスト減少,ゼロになるなら辺を削除
        cost[s][t] -= flow
        if cost[s][t] == 0:
            edges[s].remove(t)
        #t->s(逆順)のコスト増加,元がゼロなら辺を作成
        if cost[t][s] == 0:
            edges[t].add(s)
        cost[t][s] += flow
        t = s
        s = route[t]
        
    return True
while True:
    if Ford_Fulkerson(Start):
        continue
    else:
        break
#print(ans)

remaining = N-ans
print(remaining)
0