結果
問題 | No.124 門松列(3) |
ユーザー | chocorusk |
提出日時 | 2020-09-13 12:40:06 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 57 ms / 5,000 ms |
コード長 | 942 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 11,076 KB |
実行使用メモリ | 9,140 KB |
最終ジャッジ日時 | 2023-09-02 16:09:32 |
合計ジャッジ時間 | 2,378 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
8,988 KB |
testcase_01 | AC | 20 ms
8,536 KB |
testcase_02 | AC | 20 ms
8,720 KB |
testcase_03 | AC | 57 ms
9,140 KB |
testcase_04 | AC | 21 ms
8,952 KB |
testcase_05 | AC | 21 ms
8,964 KB |
testcase_06 | AC | 19 ms
8,740 KB |
testcase_07 | AC | 18 ms
8,504 KB |
testcase_08 | AC | 19 ms
8,544 KB |
testcase_09 | AC | 18 ms
8,700 KB |
testcase_10 | AC | 19 ms
8,700 KB |
testcase_11 | AC | 18 ms
8,708 KB |
testcase_12 | AC | 19 ms
8,596 KB |
testcase_13 | AC | 19 ms
8,540 KB |
testcase_14 | AC | 19 ms
8,500 KB |
testcase_15 | AC | 20 ms
8,576 KB |
testcase_16 | AC | 22 ms
8,732 KB |
testcase_17 | AC | 20 ms
8,548 KB |
testcase_18 | AC | 19 ms
8,644 KB |
testcase_19 | AC | 20 ms
8,552 KB |
testcase_20 | AC | 22 ms
8,712 KB |
testcase_21 | AC | 20 ms
8,684 KB |
testcase_22 | AC | 20 ms
8,556 KB |
testcase_23 | AC | 20 ms
8,652 KB |
testcase_24 | AC | 20 ms
8,760 KB |
testcase_25 | AC | 21 ms
8,896 KB |
testcase_26 | AC | 19 ms
8,728 KB |
testcase_27 | AC | 19 ms
8,744 KB |
testcase_28 | AC | 21 ms
8,956 KB |
testcase_29 | AC | 22 ms
8,908 KB |
ソースコード
import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines w, h=map(int, readline().split()) m=list(map(int, read().split())) from collections import deque que=deque() INF=10**9 dp=[[INF]*(w*h) for _ in range(4)] dp[0][0]=0 que.append((0, 0)) dx=[1, -1, 0, 0] dy=[0, 0, 1, -1] def is_kadomatsu(a, b, c): if a!=c and ((a<b and b>c) or (a>b and b<c)): return True else: return False while que: xy, k=que.popleft() x, y=divmod(xy, w) d=dp[k][xy] x2, y2=x-dx[k], y-dy[k] xy2=x2*w+y2 for i, (a, b) in enumerate(zip(dx, dy)): x1, y1=x+a, y+b if x1<0 or x1>=h or y1<0 or y1>=w: continue xy1=x1*w+y1 if dp[i][xy1]>d+1 and (d==0 or is_kadomatsu(m[xy2], m[xy], m[xy1])): dp[i][xy1]=d+1 que.append((xy1, i)) ans=min(dp[0][-1], dp[2][-1]) if ans==INF: print(-1) else: print(ans)