結果

問題 No.867 避難経路
ユーザー IJKTanabeIJKTanabe
提出日時 2019-09-08 20:16:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,678 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 89,500 KB
最終ジャッジ日時 2023-09-09 22:41:35
合計ジャッジ時間 15,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
78,692 KB
testcase_01 AC 295 ms
77,952 KB
testcase_02 AC 296 ms
78,092 KB
testcase_03 AC 293 ms
78,588 KB
testcase_04 AC 273 ms
79,220 KB
testcase_05 AC 334 ms
78,732 KB
testcase_06 AC 288 ms
78,812 KB
testcase_07 AC 253 ms
77,664 KB
testcase_08 AC 288 ms
78,232 KB
testcase_09 AC 380 ms
79,000 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 #

class Point:
        def __init__ (self, x, y):
                self.x = x
                self.y = y

        def nextPoints(self, x_max, y_max):
                nexts = []
                if self.x > 0: nexts.append(Point(self.x - 1, self.y))
                if self.x < x_max: nexts.append(Point(self.x + 1, self.y))
                if self.y > 0: nexts.append(Point(self.x, self.y - 1))
                if self.y < y_max: nexts.append(Point(self.x, self.y + 1))
                return nexts

HW = input()

if HW != '':
        H, W = map(int, HW.split(' '))
        gy, gx = map(lambda i: int(i) -1 , input().split(' '))
        grid = []
        for y in range(H):
                grid.append(list(map(int, input().split(' '))))
        grid_org = tuple([tuple(i) for i in grid])
        Q = int(input())
        debug_print = False

elif HW == '':
        H = 10
        W = 10
        gy = 2 - 1
        gx = 9 - 1
        Q = 1
        debug_print = True
        print ('input start x, y, and k')

        grid_org = ((9, 9, 9, 9, 9, 9, 9, 9, 9, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 9, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 0, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 1, 9, 9, 9, 9, 9, 1, 9),
                (9, 9, 1, 1, 1, 1, 1, 1, 1, 9))

result = []
for que in range(Q):

        sy, sx, k = map(int, input().split())
        sy -= 1
        sx -= 1
        grid = []
        for i in range(H):
                grid.append(list(map(lambda x: x + k**2, grid_org[i])))
        
        count = grid[sy][sx]
        grid[sy][sx] = 0

        if debug_print:        
                print()
                print('k = ' + str(k))
                print('startNum = ' + str(grid[sy][sx]))
                print ('count = ' + str(count))

        while grid[gy][gx] != 0:

                buffer = [list(i) for i in grid]

                for y in range(H):
                        for x in range(W):
                                if grid[y][x] <= 0:
                                        for p in Point(x,y).nextPoints(W -1, H -1):
                                                buffer[p.y][p.x] = grid[p.y][p.x] - 1
                count += 1

                if debug_print:
                        for y in range(H):
                                for x in range(W):
                                        color = '\033[37m'
                                        char = str(buffer[y][x])

                                        if y == sy and x == sx:
                                                color = '\033[33m'
                                                char = 'S'
                                        elif y == gy and x == gx:
                                                color = '\033[31m' 
                                        elif buffer[y][x] <= 0:
                                                color = '\033[34m'
                                        elif buffer[y][x] != grid[y][x]:
                                                color = '\033[32m'

                                        print(color, end = '')
                                        print(char.rjust(5), end = '')
                                print()

                        print('\033[0m')
                        print('count = ' + str(count))
                        input()                

                grid = tuple([tuple(i) for i in buffer])

        result.append(count)

for i in result: print(i)
0