結果

問題 No.179 塗り分け
ユーザー daku9640daku9640
提出日時 2018-05-31 00:07:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-12 20:52:27
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,056 KB
testcase_01 AC 17 ms
8,096 KB
testcase_02 AC 16 ms
8,140 KB
testcase_03 AC 16 ms
8,052 KB
testcase_04 AC 17 ms
8,148 KB
testcase_05 AC 17 ms
8,080 KB
testcase_06 WA -
testcase_07 AC 17 ms
8,212 KB
testcase_08 AC 17 ms
8,060 KB
testcase_09 AC 17 ms
8,056 KB
testcase_10 AC 19 ms
8,752 KB
testcase_11 AC 19 ms
8,716 KB
testcase_12 AC 134 ms
8,664 KB
testcase_13 AC 17 ms
8,156 KB
testcase_14 AC 16 ms
8,056 KB
testcase_15 AC 16 ms
8,076 KB
testcase_16 AC 16 ms
8,216 KB
testcase_17 AC 16 ms
8,100 KB
testcase_18 AC 18 ms
8,636 KB
testcase_19 WA -
testcase_20 AC 17 ms
8,168 KB
testcase_21 AC 17 ms
8,156 KB
testcase_22 AC 19 ms
8,172 KB
testcase_23 WA -
testcase_24 AC 17 ms
8,040 KB
testcase_25 AC 17 ms
8,060 KB
testcase_26 WA -
testcase_27 AC 21 ms
8,556 KB
testcase_28 WA -
testcase_29 AC 25 ms
8,624 KB
testcase_30 WA -
testcase_31 AC 28 ms
8,728 KB
testcase_32 AC 21 ms
8,636 KB
testcase_33 AC 33 ms
8,592 KB
testcase_34 WA -
testcase_35 AC 36 ms
8,608 KB
testcase_36 AC 17 ms
8,176 KB
testcase_37 AC 16 ms
8,168 KB
testcase_38 AC 17 ms
8,168 KB
testcase_39 AC 17 ms
8,088 KB
testcase_40 AC 17 ms
8,100 KB
testcase_41 AC 17 ms
8,076 KB
testcase_42 AC 17 ms
8,048 KB
testcase_43 AC 18 ms
8,060 KB
testcase_44 AC 18 ms
8,076 KB
testcase_45 AC 17 ms
8,092 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):
    for _ in range(len(m) // 2):
        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:])
    for i in range(len(dp)):
        dy, dx = dp.pop(i)
        y = dy - a[0]
        x = dx - a[0]
        if f(dp, y, x):
            return "YES"
        dp.reset()
    return "NO"
print(solve())
0