結果

問題 No.2731 Two Colors
ユーザー rarpipipirarpipipi
提出日時 2024-04-20 11:04:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,646 ms / 3,000 ms
コード長 1,089 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 107,392 KB
最終ジャッジ日時 2024-04-20 11:04:54
合計ジャッジ時間 19,040 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,583 ms
103,292 KB
testcase_01 AC 1,646 ms
103,464 KB
testcase_02 AC 1,617 ms
103,712 KB
testcase_03 AC 113 ms
76,876 KB
testcase_04 AC 138 ms
78,592 KB
testcase_05 AC 141 ms
77,440 KB
testcase_06 AC 229 ms
81,664 KB
testcase_07 AC 187 ms
81,308 KB
testcase_08 AC 122 ms
77,824 KB
testcase_09 AC 468 ms
94,852 KB
testcase_10 AC 113 ms
76,988 KB
testcase_11 AC 825 ms
103,896 KB
testcase_12 AC 418 ms
93,832 KB
testcase_13 AC 697 ms
99,232 KB
testcase_14 AC 303 ms
84,932 KB
testcase_15 AC 125 ms
77,316 KB
testcase_16 AC 357 ms
86,200 KB
testcase_17 AC 387 ms
88,576 KB
testcase_18 AC 176 ms
78,300 KB
testcase_19 AC 386 ms
86,520 KB
testcase_20 AC 271 ms
86,656 KB
testcase_21 AC 183 ms
78,372 KB
testcase_22 AC 610 ms
98,800 KB
testcase_23 AC 235 ms
81,764 KB
testcase_24 AC 169 ms
78,484 KB
testcase_25 AC 126 ms
76,928 KB
testcase_26 AC 431 ms
91,776 KB
testcase_27 AC 519 ms
97,280 KB
testcase_28 AC 480 ms
92,284 KB
testcase_29 AC 237 ms
80,868 KB
testcase_30 AC 258 ms
83,320 KB
testcase_31 AC 256 ms
81,904 KB
testcase_32 AC 818 ms
107,392 KB
testcase_33 AC 40 ms
52,736 KB
testcase_34 AC 40 ms
53,120 KB
testcase_35 AC 40 ms
52,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

walk=[
    (1,0),
    (-1,0),
    (0,1),
    (0,-1),
]
from heapq import heapify,heappop,heappush

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

a=[list(map(int,input().split())) for i in range(h)]
fi=[[-1]*w for i in range(h)]
fi[0][0]=0
fi[0][1]=2
fi[1][0]=2
fi[-1][-1]=1
fi[-1][-2]=3
fi[-2][-1]=3

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]

def inside(y,x):
    return 0<=y<h and 0<=x<w

for i in range(h*w):
    t_que=que[i%2]
    _,y,x=heappop(t_que)

    fi[y][x]=i%2
    # 隣がo_coloredで塗られている場合exit
    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if inside(ny,nx) and fi[ny][nx]==(1^(i%2)):
            print(i+1)
            exit()

    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if inside(ny,nx):
            if fi[ny][nx]==-1 or fi[ny][nx]&1!=i%2:
                if fi[ny][nx]==-1:
                    fi[ny][nx]=2|(i%2)
                else:
                    fi[ny][nx]|=i%2

                heappush(t_que,(a[ny][nx],ny,nx))






0