結果

問題 No.1820 NandShift
ユーザー shotoyooshotoyoo
提出日時 2022-01-21 23:09:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,315 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 77,320 KB
最終ジャッジ日時 2023-08-17 07:41:51
合計ジャッジ時間 5,440 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,368 KB
testcase_01 AC 74 ms
71,372 KB
testcase_02 WA -
testcase_03 AC 76 ms
71,164 KB
testcase_04 AC 95 ms
77,220 KB
testcase_05 AC 74 ms
71,304 KB
testcase_06 AC 78 ms
75,524 KB
testcase_07 AC 91 ms
76,492 KB
testcase_08 AC 76 ms
71,376 KB
testcase_09 WA -
testcase_10 AC 92 ms
76,196 KB
testcase_11 AC 75 ms
71,332 KB
testcase_12 AC 86 ms
76,508 KB
testcase_13 AC 139 ms
77,036 KB
testcase_14 AC 73 ms
71,400 KB
testcase_15 AC 90 ms
76,724 KB
testcase_16 AC 153 ms
77,148 KB
testcase_17 AC 81 ms
75,980 KB
testcase_18 AC 118 ms
77,220 KB
testcase_19 AC 154 ms
77,264 KB
testcase_20 AC 79 ms
75,932 KB
testcase_21 AC 84 ms
76,636 KB
testcase_22 AC 158 ms
77,320 KB
testcase_23 AC 80 ms
76,088 KB
testcase_24 AC 130 ms
77,268 KB
testcase_25 AC 161 ms
77,152 KB
testcase_26 AC 81 ms
75,692 KB
testcase_27 AC 90 ms
76,448 KB
testcase_28 AC 161 ms
77,032 KB
testcase_29 AC 75 ms
71,648 KB
testcase_30 AC 166 ms
77,236 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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 i in range(m):
    for j in range(n):
        val = (a[j]<<i)&mask
        if val:
            if base.insert(val):
                l.append((val, i, j))
if 0 in a and base.insert(mask):
    l.append((mask, None, None))
    for zind in range(len(a)):
        if a[zind]==0:
            break
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(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 = l[i-1]
            if ii is None:
                ll.append((2, ind, zind+1, ind))
                xor(0, ind)
                ind += 1
                xx ^= mask
            else:
                jj += 1
                ss[jj].append(ii)
                xx ^= v
    assert xx==x
    for i in range(1, 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
    print(len(ll))
    for item in ll:
        write(" ".join(map(str, item)))
0