結果

問題 No.2731 Two Colors
ユーザー moon17moon17
提出日時 2024-04-19 22:47:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,828 ms / 3,000 ms
コード長 708 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 191,308 KB
最終ジャッジ日時 2024-04-19 22:48:16
合計ジャッジ時間 20,091 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,759 ms
190,996 KB
testcase_01 AC 1,828 ms
191,288 KB
testcase_02 AC 1,758 ms
191,308 KB
testcase_03 AC 93 ms
77,312 KB
testcase_04 AC 137 ms
81,792 KB
testcase_05 AC 124 ms
79,360 KB
testcase_06 AC 271 ms
91,436 KB
testcase_07 AC 198 ms
94,720 KB
testcase_08 AC 115 ms
78,776 KB
testcase_09 AC 500 ms
147,884 KB
testcase_10 AC 99 ms
77,184 KB
testcase_11 AC 913 ms
143,168 KB
testcase_12 AC 493 ms
147,968 KB
testcase_13 AC 790 ms
133,224 KB
testcase_14 AC 301 ms
106,964 KB
testcase_15 AC 120 ms
78,284 KB
testcase_16 AC 458 ms
102,908 KB
testcase_17 AC 433 ms
115,400 KB
testcase_18 AC 165 ms
81,880 KB
testcase_19 AC 459 ms
103,680 KB
testcase_20 AC 327 ms
123,244 KB
testcase_21 AC 180 ms
83,088 KB
testcase_22 AC 679 ms
148,948 KB
testcase_23 AC 240 ms
92,128 KB
testcase_24 AC 181 ms
84,564 KB
testcase_25 AC 91 ms
76,416 KB
testcase_26 AC 500 ms
134,720 KB
testcase_27 AC 635 ms
149,132 KB
testcase_28 AC 527 ms
120,960 KB
testcase_29 AC 249 ms
89,816 KB
testcase_30 AC 290 ms
101,144 KB
testcase_31 AC 276 ms
91,372 KB
testcase_32 AC 924 ms
166,016 KB
testcase_33 AC 38 ms
52,224 KB
testcase_34 AC 37 ms
52,736 KB
testcase_35 AC 37 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),(h-2,w-1,0),(h-1,w-2,0)]:
  if 0<=i<h and 0<=j<w:
    q[k]+=(a[i][j],i,j),
q[0].sort()
q[1].sort()
f=[[[0]*2 for _ in range(w)]for _ in range(h)]
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:
      if c[ni][nj]==k^1:
        ng=1
      if c[ni][nj]==-1 and f[ni][nj][k]<1:
        heappush(q[k],(a[ni][nj],ni,nj))
        f[ni][nj][k]=1
  if ng:
    break
  k^=1
print(sum(i!=-1for j in c for i in j)-2)
0