結果
| 問題 |
No.861 ケーキカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-19 02:03:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 854 bytes |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 82,220 KB |
| 実行使用メモリ | 175,692 KB |
| 最終ジャッジ日時 | 2024-10-14 02:02:33 |
| 合計ジャッジ時間 | 4,779 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 20 |
ソースコード
from collections import defaultdict
c = [list(map(int, input().split())) for _ in range(5)]
s = sum([c[i][j] for i in range(5) for j in range(5)])
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
ans = abs(s - c[0][0] - c[0][0])
dq = []
dq.append((1, c[0][0]))
used = defaultdict(bool)
used[1] = True
while len(dq) > 0:
mask, score = dq.pop()
q = []
for i in range(25):
if (mask >> i) & 1 != 0:
cx, cy = i // 5, i % 5
for i in range(4):
nx = cx + dx[i]
if nx < 0 or nx >= 5:
continue
ny = cy + dy[i]
if ny < 0 or ny >= 5:
continue
nxt = mask | (1 << (nx * 5 + ny))
if (mask >> (nx * 5 + ny)) & 1 != 0 or used[nxt]:
continue
used[nxt] = True
ans = min(ans, abs(s - 2 * (score + c[nx][ny])))
dq.append((nxt, score + c[nx][ny]))
print(ans)