結果
問題 |
No.2855 Move on Grid
|
ユーザー |
|
提出日時 | 2024-08-25 14:57:46 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 979 bytes |
コンパイル時間 | 360 ms |
コンパイル使用メモリ | 82,000 KB |
実行使用メモリ | 130,896 KB |
最終ジャッジ日時 | 2024-08-25 14:58:46 |
合計ジャッジ時間 | 46,455 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 TLE * 10 -- * 19 |
ソースコード
import heapq N, M, K = map(int, input().split()) A = [list(map(int, input().split())) for i in range(N)] def slove(grid, N, M, K, X): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] changeCount = [[10 ** 18] * M for i in range(N)] changeCount[0][0] = 0 if grid[0][0] >= X else 1 pq = [(changeCount[0][0], 0, 0)] while pq: currentChange, i, j = heapq.heappop(pq) if i == N - 1 and j == M - 1: return currentChange <= K if currentChange > K: continue for di, dj in directions: ni, nj = i + di, j + dj if 0 <= ni < N and 0 <= nj < M: nextChange = currentChange + (1 if grid[ni][nj] < X else 0) if nextChange < changeCount[ni][nj]: changeCount[ni][nj] = nextChange heapq.heappush(pq, (nextChange, ni, nj)) return False low, high = 1, 10 ** 9 + 1 while low < high: mid = (low + high) // 2 if slove(A, N, M, K, mid): low = mid + 1 else: high = mid print(low - 1)