結果
問題 | No.340 雪の足跡 |
ユーザー | Tawara |
提出日時 | 2016-01-27 01:55:19 |
言語 | Python2 (2.7.18) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,574 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 30,720 KB |
最終ジャッジ日時 | 2024-09-21 17:39:21 |
合計ジャッジ時間 | 5,818 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | AC | 14 ms
6,948 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 14 ms
6,912 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 526 ms
30,720 KB |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
ソースコード
from sys import stdin from Queue import deque dx = (1,0,-1,0); dy = (0,1,0,-1); di = range(4) W,H,N = map(int,stdin.readline().split()) RH = [None]*H; MD = W*H+1 EX = [[0]*W for j in RH] EY = [[0]*H for i in [None]*W] for i in [None]*N: M = int(stdin.readline()) x,y = map(int,stdin.readline().split()) for j in [None]*M: nx,ny = map(int,stdin.readline().split()) if y == ny: if x < nx: EX[y][x]+=1; EX[y][nx]-=1 else: EX[y][nx]+=1; EX[y][x]-=1 else: if y < ny: EY[x][y]+=1; EY[x][ny]-=1 else: EY[x][ny]+=1; EY[x][y]-=1 x,y = nx,ny for j in xrange(H): for i in xrange(W-1):EX[j][i+1] += EX[j][i] for i in xrange(W): for j in xrange(H-1):EY[i][j+1] += EY[i][j] D = [[MD]*W for i in RH] 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 i in di: if dx[i] > 0: nx = x + 1 if nx < W and EX[y][x]>0 and D[y][nx] > d+1: D[y][nx] = d+1; Q.append((nx,y,d+1)) elif dx[i] < 0: nx = x - 1 if nx >= 0 and EX[y][nx]>0 and D[y][nx] > d+1: D[y][nx] = d+1; Q.append((nx,y,d+1)) elif dy[i] > 0: ny = y + 1 if ny < H and EY[x][y]>0 and D[ny][x] > d+1: D[ny][x] = d+1; Q.append((x,ny,d+1)) else: ny = y - 1 if ny >= 0 and EY[x][ny]>0 and D[ny][x] > d+1: D[ny][x] = d+1; Q.append((x,ny,d+1)) else: print "Odekakedekinai.."