結果

問題 No.2731 Two Colors
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-04-19 22:29:41
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,123 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 132,064 KB
最終ジャッジ日時 2024-04-19 22:30:09
合計ジャッジ時間 9,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,997 ms
119,344 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 142 ms
78,216 KB
testcase_04 AC 209 ms
80,736 KB
testcase_05 AC 191 ms
79,200 KB
testcase_06 AC 340 ms
86,076 KB
testcase_07 AC 283 ms
85,552 KB
testcase_08 AC 185 ms
79,284 KB
testcase_09 AC 590 ms
105,072 KB
testcase_10 AC 160 ms
78,740 KB
testcase_11 AC 1,117 ms
131,328 KB
testcase_12 AC 552 ms
105,224 KB
testcase_13 AC 1,037 ms
121,948 KB
testcase_14 AC 398 ms
92,888 KB
testcase_15 AC 194 ms
79,576 KB
testcase_16 AC 547 ms
97,708 KB
testcase_17 AC 551 ms
99,164 KB
testcase_18 AC 251 ms
81,084 KB
testcase_19 AC 526 ms
99,364 KB
testcase_20 AC 383 ms
93,500 KB
testcase_21 AC 288 ms
82,752 KB
testcase_22 AC 801 ms
116,940 KB
testcase_23 AC 365 ms
88,516 KB
testcase_24 AC 278 ms
83,508 KB
testcase_25 AC 154 ms
77,568 KB
testcase_26 AC 586 ms
103,884 KB
testcase_27 AC 700 ms
112,340 KB
testcase_28 AC 684 ms
107,664 KB
testcase_29 AC 334 ms
86,280 KB
testcase_30 AC 407 ms
91,396 KB
testcase_31 AC 390 ms
89,816 KB
testcase_32 AC 1,070 ms
132,064 KB
testcase_33 AC 38 ms
52,608 KB
testcase_34 AC 37 ms
52,864 KB
testcase_35 AC 39 ms
52,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
v=[[0]*w for i in range(h)]
v[0][0]=1
v[h-1][w-1]=2
from heapq import heappush,heappop
q1=[]
heappush(q1,(a[1][0],1,0))
heappush(q1,(a[0][1],0,1))
q2=[]
heappush(q2,(a[h-2][w-1],h-2,w-1))
heappush(q2,(a[h-1][w-2],h-1,w-2))
for i in range(1,h*w+1):
  if i%2:
    while len(q1)>0 and v[q1[0][1]][q1[0][2]]!=0:
      heappop(q1)
    if len(q1)==0:
      print(i-1)
      exit()
    z,x,y=heappop(q1)
    v[x][y]=1
    dx,dy=1,0
    for _ in range(4):
      xx,yy=x+dx,y+dy
      dx,dy=-dy,dx
      if 0<=xx<h and 0<=yy<w:
        if v[xx][yy]==0:
          heappush(q1,(a[xx][yy],xx,yy))
        if v[xx][yy]==2:
          print(i)
          exit()
  else:
    while len(q2)>0 and v[q2[0][1]][q2[0][2]]!=0:
      heappop(q2)
    if len(q2)==0:
      print(i-1)
      exit()
    z,x,y=heappop(q2)
    v[x][y]=2
    dx,dy=1,0
    for _ in range(4):
      xx,yy=x+dx,y+dy
      dx,dy=-dy,dx
      if 0<=xx<h and 0<=yy<w:
        if v[xx][yy]==0:
          heappush(q2,(a[xx][yy],xx,yy))
        if v[xx][yy]==1:
          print(i)
          exit()
0