結果
問題 | No.2928 Gridpath |
ユーザー |
![]() |
提出日時 | 2024-10-12 16:21:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 78,508 KB |
最終ジャッジ日時 | 2024-10-12 16:21:44 |
合計ジャッジ時間 | 2,559 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
from collections import defaultdict, deque, Counter# from functools import cache# import copyfrom itertools import combinations, permutations, product, accumulate, groupby, chain# from more_itertools import distinct_permutationsfrom heapq import heapify, heappop, heappushimport mathimport bisect# from pprint import pprintfrom random import randint, shuffle, randrange# from sortedcontainers import SortedSet, SortedList, SortedDictimport sys# sys.setrecursionlimit(2000000)input = lambda: sys.stdin.readline().rstrip('\n')inf = float('inf')mod1 = 10**9+7mod2 = 998244353def ceil_div(x, y): return -(-x//y)#################################################def ok(ni, nj, i, j):if not (0 <= ni < H and 0 <= nj < W) or been[ni][nj]: return Falsefor di, dj in D:if not (0 <= ni+di < H and 0 <= nj+dj < W): continueif ni+di == i and nj+dj == j: continueif been[ni+di][nj+dj]: return Falsereturn TrueH, W = map(int, input().split())si, sj = map(lambda x: int(x)-1, input().split())ti, tj = map(lambda x: int(x)-1, input().split())D = [(0, 1), (0, -1), (1, 0), (-1, 0)]been = [[False]*W for _ in range(H)]stack = [(si, sj)]ans = 0while stack:i, j = stack.pop()if i >= 0:if i == ti and j == tj:ans += 1continuebeen[i][j] = Truestack.append((~i, j))for di, dj in D:ni, nj = i+di, j+djif ok(ni, nj, i, j):stack.append((ni, nj))else:i = ~ibeen[i][j] = Falseprint(ans)