結果

問題 No.2928 Gridpath
ユーザー titia
提出日時 2024-11-18 02:53:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 756 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 36,608 KB
最終ジャッジ日時 2024-11-18 02:53:10
合計ジャッジ時間 7,352 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
from collections import Counter

H,W=map(int,input().split())
x,y=map(int,input().split())
z,w=map(int,input().split())

LIST=[(0,1),(0,-1),(1,0),(-1,0)]

Q=[[(((x,y),),x,y),1]]
DP=Counter()
DP[(((x,y),),x,y)]=1

while Q:
    #print(Q[-1])
    X,count=heappop(Q)
    S,x,y=X
    #print(S,x,y)

    if DP[S,x,y]!=count:
        continue

    for px,py in LIST:
        if 1<=x+px<=H and 1<=y+py<=W:
            if (x+px,y+py) in S:
                continue
            S2=list(S)
            for px2,py2 in LIST:
                S2.append((x+px2,y+py2))
            X=(tuple(sorted(S2)),x+px,y+py)
            DP[X]+=count
            heappush(Q,(X,DP[X]))
ANS=0
for X,x,y in DP:

    if x==z and y==w:
        ANS+=DP[X,x,y]

print(ANS)
0