結果
問題 | No.2731 Two Colors |
ユーザー |
![]() |
提出日時 | 2024-04-20 11:04:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,484 ms / 3,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 107,392 KB |
最終ジャッジ日時 | 2024-10-12 06:43:55 |
合計ジャッジ時間 | 17,305 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
walk=[(1,0),(-1,0),(0,1),(0,-1),]from heapq import heapify,heappop,heappushh,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]=0fi[0][1]=2fi[1][0]=2fi[-1][-1]=1fi[-1][-2]=3fi[-2][-1]=3que0=[]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<wfor i in range(h*w):t_que=que[i%2]_,y,x=heappop(t_que)fi[y][x]=i%2# 隣がo_coloredで塗られている場合exitfor iy,ix in walk:ny,nx=iy+y,ix+xif inside(ny,nx) and fi[ny][nx]==(1^(i%2)):print(i+1)exit()for iy,ix in walk:ny,nx=iy+y,ix+xif 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%2heappush(t_que,(a[ny][nx],ny,nx))