結果

問題 No.867 避難経路
ユーザー IJKTanabeIJKTanabe
提出日時 2019-09-17 14:55:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,599 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 86,428 KB
実行使用メモリ 86,588 KB
最終ジャッジ日時 2023-09-21 19:39:06
合計ジャッジ時間 19,390 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
76,952 KB
testcase_01 AC 175 ms
77,144 KB
testcase_02 AC 170 ms
77,204 KB
testcase_03 AC 185 ms
77,004 KB
testcase_04 AC 166 ms
77,000 KB
testcase_05 AC 187 ms
77,260 KB
testcase_06 AC 165 ms
76,920 KB
testcase_07 AC 161 ms
76,720 KB
testcase_08 AC 172 ms
76,880 KB
testcase_09 AC 205 ms
77,064 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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):
    result = []
    
    for query in queries:
        sy, sx, k = query
        
        # initialize grid for calc
        calc_grid = [[0 for i in range(W+2)] for j in range(H+2)]
        for y in range(1, H+1):
            for x in range(1, W+1):
                calc_grid[y][x] = org_grid[y-1][x-1] + k**2
            
        # initialize moving count
        count = calc_grid[sy][sx]
        calc_grid[sy][sx] = 0
        
        while calc_grid[gy][gx] != 0:
            # debug -----
            # for row in calc_grid:
            #     print(row)
            # input()
            # -----
            buffer = [list(i) for i in calc_grid]
            for y in range(1, H + 1):
                for x in range(1, W + 1):
                    if calc_grid[y][x] <= 0:
                        buffer[y-1][x] = calc_grid[y-1][x]- 1
                        buffer[y+1][x] = calc_grid[y+1][x]- 1
                        buffer[y][x-1] = calc_grid[y][x-1]- 1
                        buffer[y][x+1] = calc_grid[y][x+1]- 1
            count += 1
            calc_grid = [list(i) for i in buffer]
        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)])

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