結果

問題 No.1820 NandShift
ユーザー shotoyooshotoyoo
提出日時 2022-01-21 23:22:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,267 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 82,380 KB
最終ジャッジ日時 2023-08-17 08:06:20
合計ジャッジ時間 7,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,420 KB
testcase_01 AC 75 ms
71,404 KB
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 76 ms
71,476 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 79 ms
75,528 KB
testcase_15 AC 103 ms
77,156 KB
testcase_16 RE -
testcase_17 AC 86 ms
76,348 KB
testcase_18 AC 153 ms
77,612 KB
testcase_19 RE -
testcase_20 AC 89 ms
76,624 KB
testcase_21 AC 93 ms
76,604 KB
testcase_22 AC 228 ms
77,232 KB
testcase_23 AC 85 ms
76,620 KB
testcase_24 AC 176 ms
77,596 KB
testcase_25 AC 232 ms
77,472 KB
testcase_26 AC 86 ms
76,480 KB
testcase_27 AC 102 ms
77,448 KB
testcase_28 AC 237 ms
77,280 KB
testcase_29 AC 73 ms
71,448 KB
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

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
    print(len(ll))
    for item in ll:
        write(" ".join(map(str, item)))
0