結果

問題 No.1820 NandShift
ユーザー shotoyooshotoyoo
提出日時 2022-01-21 23:15:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,298 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2023-08-17 07:51:35
合計ジャッジ時間 5,972 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,384 KB
testcase_01 AC 69 ms
71,576 KB
testcase_02 WA -
testcase_03 AC 73 ms
71,572 KB
testcase_04 AC 107 ms
77,548 KB
testcase_05 AC 72 ms
71,348 KB
testcase_06 AC 77 ms
75,900 KB
testcase_07 AC 92 ms
76,424 KB
testcase_08 AC 72 ms
71,312 KB
testcase_09 WA -
testcase_10 AC 98 ms
76,976 KB
testcase_11 AC 74 ms
71,508 KB
testcase_12 AC 96 ms
76,604 KB
testcase_13 AC 193 ms
77,256 KB
testcase_14 AC 76 ms
75,364 KB
testcase_15 AC 99 ms
77,252 KB
testcase_16 AC 216 ms
77,644 KB
testcase_17 AC 85 ms
76,440 KB
testcase_18 AC 150 ms
77,824 KB
testcase_19 AC 225 ms
77,480 KB
testcase_20 AC 88 ms
76,520 KB
testcase_21 AC 91 ms
76,744 KB
testcase_22 AC 228 ms
77,216 KB
testcase_23 AC 83 ms
76,472 KB
testcase_24 AC 173 ms
77,480 KB
testcase_25 AC 230 ms
77,396 KB
testcase_26 AC 84 ms
76,488 KB
testcase_27 AC 102 ms
77,276 KB
testcase_28 AC 237 ms
77,596 KB
testcase_29 AC 72 ms
71,304 KB
testcase_30 AC 240 ms
77,576 KB
testcase_31 AC 83 ms
76,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO)
LI = lambda : list(map(int, input().split()))
# sys.setrecursionlimit(3*10**5+10)

class BaseF2:
    def  __init__(self, vs=None):
        """vs: list of vecotr in F2
        orig[i] : i番目の基底に対応する入力された整数
        index[i]: i番目の基底を作るときにinsertした数を復元するために必要なbaseの要素のインデックス
        """
        self.base = [0]
        self.orig = [0]
        self.index = [0]
        if vs is not None:
            for v in vs:
                self.insert(v)
    def dim(self):
        return len(self.base)
    def insert(self, v):
        # 次元が上がったかを返す
        v0 = v
        ind = 0
        for i,u in enumerate(self.base):
            if v^u < v:
                v = v^u
                ind ^= self.index[i]
            if v==0:
                return False
        ind ^= (1<<len(self.base))
        self.base.append(v)
        self.orig.append(v0)
        self.index.append(ind)
        return True
    def check(self, v):
        res = [] # vを作るためのbaseの整数の組み合わせ方
        b = 0 # vを作るためのorigの整数の組み合わせ方
        for i,u in enumerate(self.base):
            nv = min(v, v^u)
            if nv<v:
                res.append(i)
                b ^= self.index[i]
                v = nv
        return v==0 , res, b
    def clear(self):
        self.base = []

n,m = list(map(int, input().split()))
x = int(input(),2)
a = [int(input(),2) for _ in range(n)]
base = BaseF2()
mask = (1<<m) - 1
l = []
for b in range(2):
    for i in range(m):
        for j in range(n):
            if b:
                tmp = a[j]^mask
            else:
                tmp = a[j]
            val = (tmp<<i)&mask
            if val:
                if base.insert(val):
                    l.append((val, i, j, b))
def xor(i,j):
    global ind
    ll.append((2, ind, i, j))
    ind0 = ind
    ind += 1
    ll.append((2, ind, ind0, i))
    ind1 = ind
    ind += 1
    ll.append((2, ind, ind0, j))
    ind2 = ind
    ind += 1
    ll.append((2, 0, ind1, ind2))
    _a[0] = _a[i]^_a[j]
def shift(i):
    ll.append((1, i, i))
    _a[i] <<= 1

f, res, b = base.check(x)
if not f:
    print(-1)
else:
    ans = []
    ss = [[] for _ in range(2*n+1)]
    xx = 0
    used = 0
    ll = []
    ind = 1000
    _a = [0] + a + [0]*10000
    for i in range(len(base.orig)):
        if b>>i&1:
            ans.append(l[i-1])
            v,ii,jj,bb = l[i-1]
            jj += 1
            if bb:
                jj += n
            ss[jj].append(ii)
            xx ^= v
    for i in range(1, n+1):
        ll.append((2, i+n, i, i+n))
        _a[i+n] = _a[i]^mask
    assert xx==x
    for i in range(1, 2*n+1):
        tmp = ss[i]
        tmp.sort()
        p = 0
        for k in tmp:
            for _ in range(k-p):
                shift(i)
                p = k
            xor(0, i)
#     assert _a[0]==x
    assert len(ll)<=1000
    print(len(ll))
    for item in ll:
        write(" ".join(map(str, item)))
0