結果

問題 No.2731 Two Colors
ユーザー rarpipipirarpipipi
提出日時 2024-04-20 10:49:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,167 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 348,028 KB
最終ジャッジ日時 2024-04-20 10:50:06
合計ジャッジ時間 9,908 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 108 ms
77,332 KB
testcase_04 AC 163 ms
78,216 KB
testcase_05 AC 142 ms
78,584 KB
testcase_06 AC 255 ms
88,960 KB
testcase_07 AC 204 ms
84,972 KB
testcase_08 AC 124 ms
78,080 KB
testcase_09 AC 534 ms
115,344 KB
testcase_10 AC 107 ms
77,184 KB
testcase_11 AC 1,090 ms
174,848 KB
testcase_12 AC 527 ms
112,384 KB
testcase_13 AC 907 ms
155,208 KB
testcase_14 AC 305 ms
92,732 KB
testcase_15 AC 133 ms
78,592 KB
testcase_16 AC 445 ms
106,988 KB
testcase_17 AC 479 ms
108,712 KB
testcase_18 AC 189 ms
83,856 KB
testcase_19 AC 470 ms
109,900 KB
testcase_20 AC 317 ms
92,416 KB
testcase_21 AC 198 ms
83,588 KB
testcase_22 AC 720 ms
140,060 KB
testcase_23 AC 305 ms
91,648 KB
testcase_24 AC 184 ms
84,268 KB
testcase_25 AC 111 ms
77,172 KB
testcase_26 AC 486 ms
110,984 KB
testcase_27 AC 645 ms
130,268 KB
testcase_28 AC 609 ms
127,820 KB
testcase_29 AC 259 ms
88,968 KB
testcase_30 AC 310 ms
93,784 KB
testcase_31 AC 305 ms
92,632 KB
testcase_32 AC 1,048 ms
171,752 KB
testcase_33 AC 51 ms
52,864 KB
testcase_34 AC 40 ms
53,120 KB
testcase_35 AC 38 ms
348,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify,heappop,heappush

h,w=map(int,input().split())

a=[list(map(int,input().split())) for i in range(h)]

colored0=set([(0,0)])
colored1=set([(h-1,w-1)])
ad0=set([(0,0),(0,1),(1,0)])
ad1=set([(h-1,w-1),(h-2,w-1),(h-1,w-2)])
ad=[ad0,ad1]
que0=[]
que1=[]
heappush(que0,(a[0][1],0,1))
heappush(que0,(a[1][0],1,0))
heappush(que1,(a[h-1][w-2],h-1,w-2))
heappush(que1,(a[h-2][w-1],h-2,w-1))
que=[que0,que1]
colored=[colored0,colored1]
walk=[
    (1,0),
    (-1,0),
    (0,1),
    (0,-1),
]
def inside(y,x):
    return 0<=y<h and 0<=x<w

for i in range(h*w):
    t_que=que[i%2]
    t_colored=colored[i%2]
    o_colored=colored[(i%2)^1]
    t_ad=ad[i%2]
    while t_que:
        _,y,x=heappop(t_que)
        if (y,x) not in t_colored:
            break
    t_colored.add((y,x))
    # 隣がo_coloredで塗られている場合exit
    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if (ny,nx) in o_colored:
            print(i+1)
            exit()

    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if inside(ny,nx):
            if not (ny,nx) in t_ad:
                t_ad.add((ny,nx))
                heappush(t_que,(a[ny][nx],ny,nx))






0