Submission #66128651


Source Code Expand

import math
import os
import random
import sys
from typing import *
from collections import defaultdict, Counter, deque
from functools import cache, reduce
from itertools import pairwise, combinations, permutations, groupby, accumulate
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import *
from math import gcd, lcm, isqrt
from operator import add, sub, mul, floordiv, truediv, and_, or_, xor

from types import GeneratorType


def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


input = sys.stdin.readline
output = lambda x: sys.stdout.write(str(x) + "\n")
outputL = lambda x: sys.stdout.write(" ".join(map(str, x)) + "\n")

rd = random.getrandbits(32)


class SortedList:
    def __init__(self, iterable=None, _load=200):
        if iterable is None:
            iterable = []
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load]
                                for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._min_s = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        _lists = self._lists
        _mins = self._min_s
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._min_s

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._min_s

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        _load = self._load
        _lists = self._lists
        _mins = self._min_s
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        return self._len

    def __getitem__(self, index):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        return (value for _list in reversed(self._lists)
                for value in reversed(_list))

    def __repr__(self):
        return f'SortedList({list(self)})'


# 不要用Counter, set,!!!!!!!!!!!!!!!!!!!!!!!!!
# 用default-dict(int)时要^rd !!!!!!!!!!!!!!!!!!!
def sol():
    h, w = map(int, input().split())
    g = []
    for i in range(h):
        g.append(list(map(int, input().split())))
    x = h * w
    ans = 0

    def check(arr):
        n = len(arr)
        if n == 0:
            return True
        a = arr[0]
        row_a = a // w
        col_a = a % w
        for j in range(1, n):
            b = arr[j]
            row_b = b // w
            col_b = b % w
            if (abs(row_a - row_b) == 1 and col_a == col_b) or (abs(col_a - col_b) == 1 and row_a == row_b):
                if check(arr[1: j] + arr[j + 1:]):
                    return True
        return False

    for mask in range(1 << x):
        t = []
        s = 0
        for i in range(x):
            a = i // w
            b = i - a * w
            if mask >> i & 1:
                t.append(i)
            else:
                s ^= g[a][b]
        if len(t) % 2:
            continue
        if check(t):
            ans = max(ans, s)
    print(ans)


T = 1


def main():
    for i in range(T):
        sol()


main()

Submission Info

Submission Time
Task D - Domino Covering XOR
User wyzl
Language Python (PyPy 3.10-v7.3.12)
Score 425
Code Size 8861 Byte
Status AC
Exec Time 1787 ms
Memory 117328 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 51
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 174 ms 91388 KiB
00_sample_01.txt AC 146 ms 91052 KiB
00_sample_02.txt AC 1361 ms 105944 KiB
01_random_03.txt AC 615 ms 93332 KiB
01_random_04.txt AC 1073 ms 97212 KiB
01_random_05.txt AC 1359 ms 105960 KiB
01_random_06.txt AC 1528 ms 106868 KiB
01_random_07.txt AC 1787 ms 117156 KiB
01_random_08.txt AC 609 ms 93084 KiB
01_random_09.txt AC 614 ms 93312 KiB
01_random_10.txt AC 1085 ms 97340 KiB
01_random_11.txt AC 1362 ms 106088 KiB
01_random_12.txt AC 1528 ms 107028 KiB
01_random_13.txt AC 1779 ms 117108 KiB
01_random_14.txt AC 611 ms 93156 KiB
01_random_15.txt AC 132 ms 89472 KiB
01_random_16.txt AC 133 ms 89480 KiB
01_random_17.txt AC 372 ms 97152 KiB
01_random_18.txt AC 133 ms 89732 KiB
01_random_19.txt AC 1362 ms 106072 KiB
01_random_20.txt AC 197 ms 91620 KiB
01_random_21.txt AC 198 ms 91712 KiB
01_random_22.txt AC 138 ms 90916 KiB
01_random_23.txt AC 714 ms 103004 KiB
01_random_24.txt AC 1526 ms 106776 KiB
01_random_25.txt AC 268 ms 92136 KiB
01_random_26.txt AC 177 ms 91740 KiB
01_random_27.txt AC 357 ms 92000 KiB
01_random_28.txt AC 139 ms 90728 KiB
01_random_29.txt AC 270 ms 92472 KiB
01_random_30.txt AC 360 ms 95676 KiB
01_random_31.txt AC 1523 ms 106736 KiB
01_random_32.txt AC 133 ms 89388 KiB
01_random_33.txt AC 133 ms 89576 KiB
01_random_34.txt AC 198 ms 92288 KiB
01_random_35.txt AC 133 ms 89640 KiB
01_random_36.txt AC 133 ms 89480 KiB
01_random_37.txt AC 613 ms 93340 KiB
01_random_38.txt AC 1079 ms 97012 KiB
01_random_39.txt AC 1361 ms 106168 KiB
01_random_40.txt AC 1527 ms 106632 KiB
01_random_41.txt AC 1778 ms 117328 KiB
01_random_42.txt AC 610 ms 93132 KiB
01_random_43.txt AC 1363 ms 106024 KiB
01_random_44.txt AC 1364 ms 105960 KiB
01_random_45.txt AC 1361 ms 106056 KiB
01_random_46.txt AC 178 ms 91620 KiB
01_random_47.txt AC 135 ms 89424 KiB
01_random_48.txt AC 138 ms 89304 KiB
01_random_49.txt AC 147 ms 90524 KiB
01_random_50.txt AC 157 ms 91324 KiB