結果

問題 No.340 雪の足跡
ユーザー TawaraTawara
提出日時 2016-01-28 13:10:38
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,767 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 7,196 KB
実行使用メモリ 28,108 KB
最終ジャッジ日時 2023-10-21 16:30:56
合計ジャッジ時間 7,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
14,152 KB
testcase_01 AC 14 ms
7,124 KB
testcase_02 AC 14 ms
7,124 KB
testcase_03 AC 14 ms
7,124 KB
testcase_04 AC 14 ms
7,124 KB
testcase_05 AC 14 ms
7,124 KB
testcase_06 AC 14 ms
7,124 KB
testcase_07 AC 14 ms
7,124 KB
testcase_08 AC 14 ms
7,124 KB
testcase_09 AC 14 ms
7,124 KB
testcase_10 AC 14 ms
7,124 KB
testcase_11 AC 27 ms
7,216 KB
testcase_12 AC 23 ms
7,228 KB
testcase_13 AC 30 ms
7,280 KB
testcase_14 AC 450 ms
10,032 KB
testcase_15 AC 558 ms
10,212 KB
testcase_16 AC 322 ms
8,292 KB
testcase_17 AC 783 ms
10,812 KB
testcase_18 AC 613 ms
10,800 KB
testcase_19 AC 783 ms
10,800 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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())
        x = B[0]%W; y = B[0]/W;
        for j in xrange(1,M+1):
            nx = B[j]%W; ny = B[j]/W
            if y == ny:
                if x < nx: 
                    for k in xrange(x+1,nx+1): EX[y][k]+=1
                else:
                    for k in xrange(nx+1,x+1): EX[y][k]+=1
            else:
                if y < ny:
                    for k in xrange(y+1,ny+1): EY[x][k]+=1
                else:
                    for k in xrange(ny+1,y+1): EY[x][k]+=1
            x = nx; y = ny
    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.."
        
if __name__ == "__main__":
    main()
0