結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2024-04-19 23:19:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,536 bytes |
| コンパイル時間 | 276 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 257,984 KB |
| 最終ジャッジ日時 | 2024-10-11 17:53:05 |
| 合計ジャッジ時間 | 16,098 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 16 WA * 17 |
ソースコード
import heapq
H,W = map(int,input().split())
A = [ list(map(int,input().split())) for i in range(H) ]
dic = {}
lis = []
for i in range(H):
for j in range(W):
lis.append( A[i][j] )
lis.sort()
for i in range(len(lis)):
dic[lis[i]] = i
for i in range(H):
for j in range(W):
A[i][j] = dic[A[i][j]]
rev = [0] * (H*W)
for i in range(H):
for j in range(W):
rev[A[i][j]] = (i,j)
color = [[-1] * W for i in range(H)]
state = [[0] * W for i in range(H)]
q0 = []
q1 = []
color[0][0] = 1
q1.append( A[0][0] )
color[H-1][W-1] = 0
q0.append( A[H-1][W-1] )
ans = 0
for i in range(H*W+1):
flag = False
if i % 2 == 0:
num = heapq.heappop(q0)
x,y = rev[num]
color[x][y] = 0
for xx,yy in ( (x-1,y),(x+1,y),(x,y-1),(x,y+1) ):
if not (0 <= xx < H and 0 <= yy < W):
continue
if state[xx][yy] & 1 == 0:
state[xx][yy] |= 1
heapq.heappush( q0 , A[xx][yy])
if color[xx][yy] == 1:
flag = True
else:
num = heapq.heappop(q1)
x,y = rev[num]
color[x][y] = 1
for xx,yy in ( (x-1,y),(x+1,y),(x,y-1),(x,y+1) ):
if not (0 <= xx < H and 0 <= yy < W):
continue
if state[xx][yy] & 2 == 0:
state[xx][yy] |= 2
heapq.heappush( q1 , A[xx][yy])
if color[xx][yy] == 0:
flag = True
ans += 1
if flag:
break
print (ans - 3)
SPD_9X2