結果

問題 No.640 76本のトロンボーン
ユーザー ryutaro-albert2005ryutaro-albert2005
提出日時 2018-02-09 17:41:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,297 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 49,528 KB
最終ジャッジ日時 2024-04-16 18:17:57
合計ジャッジ時間 9,353 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

class Solver(object):
    def __init__(self):
        self.max_depth = 0

    def puts(self, ind, muki, box, n, depth=0):
        i = ind // n
        j = ind % n
        if box[i, j] != 0:
            if not ind == n**2-1:
                self.puts(ind+1, 0, box, n, depth)
                self.puts(ind+1, 1, box, n, depth)
        else:
            new_box = box.copy()
            new_depth = depth
            if muki == 0:
                room = new_box[i:i+n-1, j]
            else:
                room = new_box[i, j:j+n-1]
            if room.sum() >= 1 or room.size != n-1:
                pass
            else:
                room += 1
                new_depth = depth + 1
                for k in range(ind+1, n**2):
                    self.puts(k, 0, new_box, n, new_depth)
                    self.puts(k, 1, new_box, n, new_depth)
        if self.max_depth < depth:
            self.max_depth = depth

    def solve(self, box, n):
        self.puts(0, 0, box, n)
        self.puts(0, 1, box, n)
        return self.max_depth
    
n = int(input())
box = []
for i in range(n):
    row = list(input().strip())
    row = (np.array(row)=='#').astype('i')
    box.append(row)
box = np.array(box)

solver = Solver()
ans = solver.solve(box, n)

print(str(ans)+'\n')
0