結果
問題 |
No.2731 Two Colors
|
ユーザー |
|
提出日時 | 2024-04-19 22:34:06 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 694 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 82,288 KB |
実行使用メモリ | 120,620 KB |
最終ジャッジ日時 | 2024-10-11 16:11:17 |
合計ジャッジ時間 | 17,984 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | WA * 30 TLE * 3 |
ソースコード
from heapq import* (h,w),*a=[[*map(int,s.split())]for s in open(0)] c=[[-1]*w for _ in range(h)] c[0][0]=1 c[-1][-1]=0 q=[[]for _ in range(2)] for i,j,k in[(1,0,1),(0,1,1),(w-2,h-1,0),(w-1,h-2,0)]: if 0<=i<h and 0<=j<w: q[k]+=(a[i][j],i,j), q[0].sort() q[1].sort() k=1 while q[k]: p,i,j=heappop(q[k]) if c[i][j]!=-1: continue c[i][j]=k ng=0 for di,dj in[(-1,0),(1,0),(0,1),(0,-1)]: ni,nj=i+di,j+dj if 0<=ni<h and 0<=nj<w and c[ni][nj]==k^1: ng=1 if ng: break for di,dj in[(-1,0),(1,0),(0,1),(0,-1)]: ni,nj=i+di,j+dj if 0<=ni<h and 0<=nj<w and c[ni][nj]==-1: heappush(q[k],(a[ni][nj],ni,nj)) k^=1 print(sum(i!=-1for j in c for i in j)-2)