結果
問題 | No.2328 Build Walls |
ユーザー | cozy_sauna |
提出日時 | 2023-05-28 14:50:36 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,156 bytes |
コンパイル時間 | 578 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 220,160 KB |
最終ジャッジ日時 | 2024-06-08 06:18:24 |
合計ジャッジ時間 | 31,538 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
17,664 KB |
testcase_01 | AC | 35 ms
12,160 KB |
testcase_02 | AC | 37 ms
12,032 KB |
testcase_03 | AC | 37 ms
12,160 KB |
testcase_04 | AC | 38 ms
12,160 KB |
testcase_05 | AC | 36 ms
12,032 KB |
testcase_06 | AC | 37 ms
12,160 KB |
testcase_07 | AC | 37 ms
12,160 KB |
testcase_08 | AC | 38 ms
12,288 KB |
testcase_09 | AC | 38 ms
12,032 KB |
testcase_10 | AC | 37 ms
12,160 KB |
testcase_11 | AC | 38 ms
12,288 KB |
testcase_12 | AC | 36 ms
12,160 KB |
testcase_13 | AC | 784 ms
73,344 KB |
testcase_14 | WA | - |
testcase_15 | AC | 899 ms
66,560 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 104 ms
18,432 KB |
testcase_20 | WA | - |
testcase_21 | AC | 370 ms
44,928 KB |
testcase_22 | WA | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | WA | - |
testcase_27 | TLE | - |
testcase_28 | AC | 688 ms
73,984 KB |
testcase_29 | TLE | - |
testcase_30 | AC | 1,483 ms
125,184 KB |
testcase_31 | AC | 1,347 ms
110,720 KB |
testcase_32 | WA | - |
testcase_33 | TLE | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
from sys import setrecursionlimit, stdin from collections import defaultdict, deque, Counter from itertools import permutations, combinations, product from functools import lru_cache from bisect import bisect_left, bisect_right from heapq import heappush, heappop from copy import copy, deepcopy from decimal import Decimal from random import random, randrange # from pypyjit import set_param # set_param('max_unroll_recursion=-1') setrecursionlimit(1 << 20) readline = stdin.readline INF = 10 ** 18 MOD = 998244353 # MOD = 1000000007 ALP = 26 ''' Input ''' def I(): return int(readline()) def ST(): return readline()[:-1] def LI(): return list(map(int, readline().split())) def LII(): return list(map(lambda x: int(x) - 1, readline().split())) def LF(x, func): return [func() for _ in [0] * x] def SPI(): return map(int, readline().split()) def SPII(): return map(lambda x: int(x) - 1, readline().split()) def FIE(x): return [readline()[:-1] for _ in [0] * x] ''' Array ''' def cmin(dp, i, x): if x < dp[i]: dp[i] = x def cmax(dp, i, x): if x > dp[i]: dp[i] = x ''' Alphabet ''' def alp_a_to_i(s): return ord(s) - ord('a') def alp_A_to_i(s): return ord(s) - ord('A') def alp_i_to_a(i): return chr(ord('a') + i) def alp_i_to_A(i): return chr(ord('A') + i) ''' Other''' def nynx(y, x, H, W): return [(y + dy, x + dx) for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)] if 0 <= y + dy < H and 0 <= x + dx < W] def gen(x, *args): if len(args) == 1: return [x] * args[0] if len(args) == 2: return [[x] * args[1] for _ in [0] * args[0]] if len(args) == 3: return [[[x] * args[2] for _ in [0] * args[1]] for _ in [0] * args[0]] if len(args) == 4: return [[[[x] * args[3] for _ in [0] * args[2]] for _ in [0] * args[1]] for _ in [0] * args[0]] ''' Output ''' def pprint(E): print() for e in E: print(e) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") def yn(x): print("Yes" if x else "No") def YN(x): print("YES" if x else "NO") ############################################################################################### class Dikstra: def __init__(self, N, node): self.node = node self.N = N def get(self, start): self.start_node = start dist, done = [10 ** 18] * self.N, [0] * self.N hq = [(0, start)] # (cost, node) dist[start] = 0 while hq: c, v = heappop(hq) if done[v]: continue done[v] = 1 for to, cost in self.node[v]: new_cost = dist[v] + cost if not done[to] and new_cost < dist[to]: dist[to] = new_cost heappush(hq, (dist[to], to)) return dist H, W = SPI() A = LF(H - 2, LI) A = [[-1] * W] + A + [[-1] * W] def f(i, j): return i * W + j def inside(y, x): return 0 <= y < H and 0 <= x < W node = [[] for _ in range(H * W)] for i in range(1, H - 1): for j in range(W): if A[i][j] == -1: continue if inside(i + 1, j) and A[i + 1][j] != -1: node[f(i, j)].append((f(i + 1, j), A[i + 1][j])) if inside(i - 1, j) and A[i - 1][j] != -1: node[f(i, j)].append((f(i - 1, j), A[i - 1][j])) if inside(i, j + 1) and A[i][j + 1] != -1: node[f(i, j)].append((f(i, j + 1), A[i][j + 1])) if inside(i + 1, j + 1) and A[i + 1][j + 1] != -1: node[f(i, j)].append((f(i + 1, j + 1), A[i + 1][j + 1])) if inside(i - 1, j + 1) and A[i - 1][j + 1] != -1: node[f(i, j)].append((f(i - 1, j + 1), A[i - 1][j + 1])) dist = [INF] * (H * W) done = [0] * (H * W) hq = [] for i in range(1, H - 1): if A[i][0] != -1: heappush(hq, (A[i][0], f(i, 0))) dist[f(i, 0)] = A[i][0] while hq: c, v = heappop(hq) if done[v]: continue done[v] = 1 for to, cost in node[v]: new_cost = dist[v] + cost if not done[to] and new_cost < dist[to]: dist[to] = new_cost heappush(hq, (dist[to], to)) ans = INF for i in range(1, H - 1): ans = min(ans, dist[f(i, W - 1)]) if ans == INF: ans = -1 print(ans)