結果

問題 No.179 塗り分け
ユーザー daku9640daku9640
提出日時 2018-05-31 00:37:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 131 ms / 3,000 ms
コード長 1,745 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 8,804 KB
最終ジャッジ日時 2023-09-30 20:59:00
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,052 KB
testcase_01 AC 16 ms
8,052 KB
testcase_02 AC 16 ms
8,044 KB
testcase_03 AC 16 ms
8,036 KB
testcase_04 AC 16 ms
8,084 KB
testcase_05 AC 16 ms
8,100 KB
testcase_06 AC 16 ms
8,060 KB
testcase_07 AC 15 ms
7,968 KB
testcase_08 AC 16 ms
8,028 KB
testcase_09 AC 16 ms
8,044 KB
testcase_10 AC 18 ms
8,684 KB
testcase_11 AC 18 ms
8,804 KB
testcase_12 AC 131 ms
8,720 KB
testcase_13 AC 16 ms
7,992 KB
testcase_14 AC 16 ms
8,140 KB
testcase_15 AC 16 ms
8,096 KB
testcase_16 AC 16 ms
8,140 KB
testcase_17 AC 15 ms
8,040 KB
testcase_18 AC 17 ms
8,540 KB
testcase_19 AC 17 ms
8,512 KB
testcase_20 AC 16 ms
7,992 KB
testcase_21 AC 16 ms
8,072 KB
testcase_22 AC 18 ms
7,992 KB
testcase_23 AC 17 ms
8,440 KB
testcase_24 AC 16 ms
7,996 KB
testcase_25 AC 16 ms
8,152 KB
testcase_26 AC 17 ms
8,068 KB
testcase_27 AC 19 ms
8,432 KB
testcase_28 AC 17 ms
8,600 KB
testcase_29 AC 23 ms
8,532 KB
testcase_30 AC 20 ms
8,596 KB
testcase_31 AC 26 ms
8,652 KB
testcase_32 AC 20 ms
8,644 KB
testcase_33 AC 30 ms
8,588 KB
testcase_34 AC 19 ms
8,584 KB
testcase_35 AC 33 ms
8,528 KB
testcase_36 AC 16 ms
8,048 KB
testcase_37 AC 16 ms
8,112 KB
testcase_38 AC 16 ms
7,968 KB
testcase_39 AC 16 ms
8,040 KB
testcase_40 AC 16 ms
8,152 KB
testcase_41 AC 16 ms
8,136 KB
testcase_42 AC 16 ms
8,132 KB
testcase_43 AC 16 ms
8,080 KB
testcase_44 AC 18 ms
8,032 KB
testcase_45 AC 16 ms
8,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class LIST:
    __slots__ = ['li', 'len_li', 'b', 'ma', 'cnt']
    def __init__(self, li):
        self.li = li
        self.len_li = len(li)
        self.b = [0] * self.len_li
        self.ma = {a:i for i, a in enumerate(li)}
        self.cnt = 0
    def __len__(self):
        return self.b.count(0)
    def reset(self):
        self.b = [0] * self.len_li
        self.cnt = 0
    def pop(self, a):
        self.b[a] = 1
        return self.li[a]
    def popleft(self):
        for i in range(self.cnt, self.len_li):
            if self.b[i] == 0:
                self.b[i] = 1
                for j in range(i + 1, self.len_li):
                    if self.b[j] == 0:
                        self.cnt = j
                        break
                return self.li[i]
        return (-100, -100)
    def find(self, a):
        if a in self.ma:
            return True
        return False
    def remove(self, a):
        if self.find(a):
            self.b[self.ma[a]] = 1
            return True
        return False
def f(m, y, x, n):
    for _ in range(n):
        a = m.popleft()
        ny = y + a[0]
        nx = x + a[1]
        if not m.remove((ny, nx)):
            return False
    return True
def solve():
    h, w = map(int, input().split())
    s = tuple(input() for _ in range(h))
    c_cnt = sum(a.count('#') for a in s)
    if c_cnt == 0 or c_cnt & 1:
        return "NO"
    m = tuple((i, j) for i in range(h) for j in range(w) if s[i][j] == '#')
    a = m[0]
    dp = LIST(m[1:])
    n = len(dp) // 2
    for i in range(len(dp)):
        dy, dx = m[i + 1]
        dp.b[i] = 1
        y = dy - a[0]
        x = dx - a[1]
        if f(dp, y, x, n):
            return "YES"
        dp.reset()
    return "NO"
print(solve())
0