結果
問題 | No.340 雪の足跡 |
ユーザー | Tawara |
提出日時 | 2016-01-10 16:47:14 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 537 ms / 1,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 2,164 ms |
コンパイル使用メモリ | 77,108 KB |
実行使用メモリ | 114,868 KB |
最終ジャッジ日時 | 2023-10-19 19:47:17 |
合計ジャッジ時間 | 12,536 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
77,740 KB |
testcase_01 | AC | 95 ms
77,740 KB |
testcase_02 | AC | 89 ms
77,740 KB |
testcase_03 | AC | 95 ms
77,740 KB |
testcase_04 | AC | 92 ms
77,740 KB |
testcase_05 | AC | 97 ms
77,740 KB |
testcase_06 | AC | 92 ms
77,740 KB |
testcase_07 | AC | 99 ms
77,740 KB |
testcase_08 | AC | 97 ms
77,740 KB |
testcase_09 | AC | 95 ms
77,740 KB |
testcase_10 | AC | 99 ms
77,740 KB |
testcase_11 | AC | 131 ms
79,792 KB |
testcase_12 | AC | 122 ms
80,392 KB |
testcase_13 | AC | 118 ms
80,416 KB |
testcase_14 | AC | 157 ms
82,844 KB |
testcase_15 | AC | 168 ms
84,196 KB |
testcase_16 | AC | 139 ms
82,128 KB |
testcase_17 | AC | 172 ms
84,092 KB |
testcase_18 | AC | 170 ms
84,552 KB |
testcase_19 | AC | 172 ms
84,096 KB |
testcase_20 | AC | 326 ms
107,044 KB |
testcase_21 | AC | 181 ms
82,000 KB |
testcase_22 | AC | 129 ms
94,308 KB |
testcase_23 | AC | 370 ms
105,976 KB |
testcase_24 | AC | 253 ms
98,388 KB |
testcase_25 | AC | 278 ms
106,112 KB |
testcase_26 | AC | 144 ms
81,704 KB |
testcase_27 | AC | 117 ms
79,724 KB |
testcase_28 | AC | 160 ms
82,756 KB |
testcase_29 | AC | 417 ms
101,064 KB |
testcase_30 | AC | 332 ms
96,148 KB |
testcase_31 | AC | 491 ms
111,476 KB |
testcase_32 | AC | 536 ms
114,756 KB |
testcase_33 | AC | 493 ms
114,528 KB |
testcase_34 | AC | 537 ms
114,756 KB |
testcase_35 | AC | 451 ms
114,828 KB |
testcase_36 | AC | 437 ms
114,868 KB |
ソースコード
from sys import stdin from Queue import deque 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.."