結果

問題 No.867 避難経路
ユーザー IJKTanabeIJKTanabe
提出日時 2019-09-17 21:25:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,917 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 158,012 KB
最終ジャッジ日時 2023-09-21 20:17:27
合計ジャッジ時間 17,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
82,184 KB
testcase_01 AC 115 ms
77,064 KB
testcase_02 AC 120 ms
77,040 KB
testcase_03 AC 119 ms
77,128 KB
testcase_04 AC 118 ms
77,004 KB
testcase_05 AC 123 ms
77,076 KB
testcase_06 AC 117 ms
76,888 KB
testcase_07 AC 115 ms
77,104 KB
testcase_08 AC 114 ms
76,944 KB
testcase_09 AC 120 ms
77,060 KB
testcase_10 AC 1,425 ms
77,456 KB
testcase_11 AC 940 ms
77,320 KB
testcase_12 AC 1,252 ms
77,256 KB
testcase_13 AC 970 ms
77,272 KB
testcase_14 AC 799 ms
77,268 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def hinan_keiro(H, W, gy, gx, org_grid, queries):
    H = H + 2
    W = W + 2
    goal = (gy * W) + gx
    result = []
    
    for query in queries:
        sy, sx, k = query
        start = (sy * W) + sx
        k = k**2
        
        # initialize calc grid
        calc_grid = [0]*W
        for row in org_grid:
            calc_grid += [0] + list(map(lambda val: val + k, row)) + [0]
        calc_grid += [0]*W
        
        # initialize count
        count = calc_grid[start] - 1
        calc_grid[start] = 1
        
        # initialize decrease points
        dec_points = tuple([start])
        
        while calc_grid[goal] != 0:
            # debug -----
            # for r in range(0, H):
            #     print(calc_grid[r * W:r * W + W])   
            # input()
            # -----

            # copy decrease points to buffer
            buffer = set(dec_points)

            for point in dec_points:
                calc_grid[point] -= 1
                if calc_grid[point] == 0:
                    buffer.remove(point)
                    for new_point in [point - 1, point + 1, point - W, point + W]:
                        if calc_grid[new_point] > 0:
                            buffer.add(new_point)
            dec_points = tuple(buffer)                 
            count += 1
        result.append(count)
    return result

if __name__ == '__main__':
    H, W = map(int, input().split(' '))
    gy, gx = map(int, input().split(' '))

    grid = tuple([
        tuple(map(int, input().split(' ')))
        for i in range(H)])

    Q = int(input())
    queries = tuple([
        tuple(map(int, input().split(' ')))
        for i in range(Q)])
    
    # import time
    # start_time = time.time()

    result = hinan_keiro(H, W, gy, gx, grid, queries)
    for i in result: print(i)

    # process_time = time.time() - start_time
    # print('process_time = ' + str(process_time))

0