結果
| 問題 |
No.1324 Approximate the Matrix
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:32:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 913 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 83,328 KB |
| 最終ジャッジ日時 | 2025-06-12 15:34:36 |
| 合計ジャッジ時間 | 5,784 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 33 |
ソースコード
import heapq
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [list(map(int, input().split())) for _ in range(n)]
sum_p_squared = sum(p * p for row in P for p in row)
remaining_supply = A.copy()
remaining_demand = B.copy()
heap = []
for i in range(n):
for j in range(n):
if remaining_supply[i] > 0 and remaining_demand[j] > 0:
initial_m = 1 - 2 * P[i][j]
heapq.heappush(heap, (initial_m, i, j))
sum_m = 0
for _ in range(k):
while True:
if not heap:
break # This should not happen as per problem statement
m, i, j = heapq.heappop(heap)
if remaining_supply[i] > 0 and remaining_demand[j] > 0:
break
sum_m += m
remaining_supply[i] -= 1
remaining_demand[j] -= 1
next_m = m + 2
heapq.heappush(heap, (next_m, i, j))
print(sum_p_squared + sum_m)
gew1fw