結果

問題 No.340 雪の足跡
ユーザー TawaraTawara
提出日時 2016-01-27 11:53:50
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,744 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,108 KB
実行使用メモリ 6,972 KB
最終ジャッジ日時 2023-10-21 16:24:23
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from Queue import deque
def main():
    dxy = ((1,0),(0,1),(-1,0),(0,-1))
    W,H,N = map(int,stdin.readline().split())
    MD = W*H+1
    EX = [[0]*(W+2) for j in xrange(H)]
    EY = [[0]*(H+2) for i in xrange(W)]
    for i in xrange(N):
        M = int(stdin.readline())
        B = map(int,stdin.readline().split())
        for j in xrange(M):
            x = B[j]%W; y = B[j]/W; nx = B[j+1]%W; ny = B[j+1]/W
            if y == ny:
                if x < nx: EX[y][x+1]+=1; EX[y][nx+1]-=1
                else: EX[y][nx+1]+=1; EX[y][x+1]-=1
            else:
                if y < ny: EY[x][y+1]+=1; EY[x][ny+1]-=1
                else: EY[x][ny+1]+=1; EY[x][y+1]-=1
            x,y = nx,ny
    for j in xrange(H):
        for i in xrange(1,W):EX[j][i+1] += EX[j][i]
    for i in xrange(W):
        for j in xrange(1,H):EY[i][j+1] += EY[i][j]
    D = [[MD]*W for i in xrange(H)]
    D[0][0] = 0; G = W+H-2
    Q = deque([(0,0,0)])
    while Q:
        x,y,d = Q.popleft()
        if x+y == G:
            print d; break
        for dx,dy in dxy:
            if dx > 0:
                nx = x + 1
                if EX[y][nx]>0 and D[y][nx] > d+1:
                    D[y][nx] = d+1; Q.append((nx,y,d+1))
            elif dx < 0:
                nx = x - 1
                if EX[y][x]>0 and D[y][nx] > d+1:
                    D[y][nx] = d+1; Q.append((nx,y,d+1))
            elif dy > 0:
                ny = y + 1
                if EY[x][ny]>0 and D[ny][x] > d+1:
                    D[ny][x] = d+1; Q.append((x,ny,d+1))
            else:
                ny = y - 1
                if EY[x][y]>0 and D[ny][x] > d+1:
                    D[ny][x] = d+1; Q.append((x,ny,d+1))
    else:
        print "Odekakedekinai.."
0