結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,092 KB
testcase_01 AC 17 ms
8,096 KB
testcase_02 WA -
testcase_03 AC 16 ms
8,080 KB
testcase_04 WA -
testcase_05 AC 16 ms
8,088 KB
testcase_06 WA -
testcase_07 AC 16 ms
8,012 KB
testcase_08 AC 17 ms
8,104 KB
testcase_09 AC 17 ms
8,032 KB
testcase_10 AC 20 ms
8,716 KB
testcase_11 AC 20 ms
8,732 KB
testcase_12 AC 122 ms
8,748 KB
testcase_13 AC 17 ms
8,104 KB
testcase_14 WA -
testcase_15 AC 17 ms
8,088 KB
testcase_16 AC 17 ms
8,088 KB
testcase_17 AC 17 ms
8,096 KB
testcase_18 AC 19 ms
8,512 KB
testcase_19 AC 18 ms
8,464 KB
testcase_20 AC 17 ms
8,076 KB
testcase_21 AC 17 ms
8,084 KB
testcase_22 AC 19 ms
8,012 KB
testcase_23 AC 22 ms
8,436 KB
testcase_24 AC 18 ms
8,032 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 21 ms
8,556 KB
testcase_28 WA -
testcase_29 AC 24 ms
8,480 KB
testcase_30 WA -
testcase_31 AC 28 ms
8,556 KB
testcase_32 WA -
testcase_33 AC 31 ms
8,596 KB
testcase_34 WA -
testcase_35 AC 34 ms
8,732 KB
testcase_36 AC 17 ms
8,152 KB
testcase_37 AC 17 ms
8,156 KB
testcase_38 AC 17 ms
8,032 KB
testcase_39 AC 17 ms
8,132 KB
testcase_40 AC 17 ms
8,012 KB
testcase_41 AC 16 ms
8,080 KB
testcase_42 AC 16 ms
8,036 KB
testcase_43 AC 17 ms
8,132 KB
testcase_44 AC 18 ms
8,108 KB
testcase_45 AC 17 ms
8,212 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]
        y = dy - a[0]
        x = dx - a[1]
        if f(dp, y, x, n):
            return "YES"
        dp.reset()
    return "NO"
print(solve())
0