結果

問題 No.2731 Two Colors
ユーザー moon17moon17
提出日時 2024-04-19 22:34:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 694 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 120,500 KB
最終ジャッジ日時 2024-04-19 22:34:46
合計ジャッジ時間 18,704 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 39 ms
52,736 KB
testcase_34 AC 39 ms
52,736 KB
testcase_35 AC 40 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0