Submission #22260892


Source Code Expand

import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
# from math import isqrt, prod,comb  # python3.8用(notpypy)
#from bisect import bisect_left,bisect_right
#from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError
# numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k  # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)

class tuplepacking:
    def __init__(self,maxsizelist):
        self.n=len(maxsizelist)
        self.maxsizelist=tuple(maxsizelist)
    
    def packing(self,*tuples):
        ans=0
        for size,tu in zip(self.maxsizelist,tuples):
            ans*=size
            ans+=tu
        return ans
    
    def unpacking(self,value):
        ans=[0]*self.n
        for i in range(self.n)[::-1]:
            value,ans[i]=divmod(value,self.maxsizelist[i])
        return ans

def main():
    r, c = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(r)]
    B = [list(map(int, input().split())) for i in range(r-1)]

    mindist = [[10**10] * c for i in range(r)]
    fixed = [[False] * c for i in range(r)]
    hq = []
    #tp=tuplepacking([10**10,500,500])
    heappush(hq, (1, 0, 0))
    while hq:
        dist, x, y = heappop(hq)
        if x == r-1 and y == c-1:
            print(dist-1)
            return
        if fixed[x][y]:
            continue
        fixed[x][y] = True
        
        if y > 0 and not dist+A[x][y-1] >= mindist[x][y-1]:
            heappush(hq, (dist+A[x][y-1], x,y-1))
            mindist[x][y-1] = dist+A[x][y-1]
        if y < c-1 and not dist+A[x][y] >= mindist[x][y+1]:
            heappush(hq, (dist+A[x][y], x,y+1))
            mindist[x][y+1] = dist+A[x][y]
        if x < r-1 and not dist+B[x][y] >= mindist[x+1][y]:
            heappush(hq, (dist+B[x][y], x+1,y))
            mindist[x+1][y] = dist+B[x][y]
        for i in range(1,x+1):
            if dist+1+i >=mindist[x-i][y]:
                continue
            heappush(hq, (dist+1+i, x-i,y))
            mindist[x-i][y]=dist+1+i




    
        


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task E - Sneaking
User ansain
Language PyPy3 (7.3.0)
Score 500
Code Size 2797 Byte
Status AC
Exec Time 1728 ms
Memory 106612 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 01_sample.txt, 02_sample.txt, 03_sample.txt
All 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_random.txt, 05_random.txt, 06_random.txt, 07_random.txt, 08_random.txt, 09_random.txt, 10_random.txt, 11_random.txt, 12_random.txt, 13_random.txt, 14_random.txt, 15_random.txt, 16_random.txt, 17_random.txt, 18_random.txt, 19_random.txt, 20_random.txt, 21_random.txt, 22_random.txt, 23_random.txt, 24_max.txt, 25_max.txt, 26_max.txt, 27_max.txt, 28_zigzag.txt, 29_zigzag.txt
Case Name Status Exec Time Memory
01_sample.txt AC 71 ms 65656 KiB
02_sample.txt AC 60 ms 65964 KiB
03_sample.txt AC 60 ms 65244 KiB
04_random.txt AC 105 ms 75156 KiB
05_random.txt AC 341 ms 80056 KiB
06_random.txt AC 147 ms 76820 KiB
07_random.txt AC 62 ms 65904 KiB
08_random.txt AC 61 ms 65948 KiB
09_random.txt AC 133 ms 75272 KiB
10_random.txt AC 82 ms 74576 KiB
11_random.txt AC 283 ms 79572 KiB
12_random.txt AC 167 ms 77200 KiB
13_random.txt AC 895 ms 94104 KiB
14_random.txt AC 189 ms 77408 KiB
15_random.txt AC 153 ms 76904 KiB
16_random.txt AC 569 ms 86908 KiB
17_random.txt AC 104 ms 74880 KiB
18_random.txt AC 77 ms 73812 KiB
19_random.txt AC 184 ms 77204 KiB
20_random.txt AC 915 ms 90152 KiB
21_random.txt AC 79 ms 67756 KiB
22_random.txt AC 281 ms 79976 KiB
23_random.txt AC 82 ms 74212 KiB
24_max.txt AC 1480 ms 99740 KiB
25_max.txt AC 1728 ms 106612 KiB
26_max.txt AC 653 ms 84268 KiB
27_max.txt AC 667 ms 84544 KiB
28_zigzag.txt AC 1242 ms 94264 KiB
29_zigzag.txt AC 1217 ms 94192 KiB