結果

問題 No.1820 NandShift
ユーザー zkouzkou
提出日時 2021-08-29 10:19:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 77,412 KB
最終ジャッジ日時 2023-08-17 04:01:10
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,480 KB
testcase_01 AC 100 ms
71,688 KB
testcase_02 AC 97 ms
71,680 KB
testcase_03 AC 97 ms
71,496 KB
testcase_04 AC 96 ms
71,312 KB
testcase_05 AC 93 ms
71,648 KB
testcase_06 AC 95 ms
71,660 KB
testcase_07 AC 105 ms
76,432 KB
testcase_08 AC 94 ms
71,800 KB
testcase_09 AC 99 ms
76,364 KB
testcase_10 AC 108 ms
77,288 KB
testcase_11 AC 93 ms
71,404 KB
testcase_12 AC 95 ms
71,692 KB
testcase_13 AC 95 ms
71,772 KB
testcase_14 AC 99 ms
71,436 KB
testcase_15 AC 92 ms
71,648 KB
testcase_16 AC 109 ms
77,364 KB
testcase_17 AC 95 ms
71,464 KB
testcase_18 AC 105 ms
77,412 KB
testcase_19 AC 107 ms
77,244 KB
testcase_20 AC 96 ms
71,404 KB
testcase_21 AC 95 ms
71,492 KB
testcase_22 AC 95 ms
71,864 KB
testcase_23 AC 99 ms
71,520 KB
testcase_24 AC 101 ms
72,276 KB
testcase_25 AC 105 ms
77,232 KB
testcase_26 AC 96 ms
71,600 KB
testcase_27 AC 100 ms
72,252 KB
testcase_28 AC 114 ms
77,048 KB
testcase_29 AC 96 ms
71,556 KB
testcase_30 AC 104 ms
76,460 KB
testcase_31 AC 108 ms
76,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


N, M = map(int, input().split())
X = int(input(), 2)
As = [int(input(), 2) for _ in range(N)]

TMP1 = 10 ** 7
TMP2 = 10 ** 7 + 1

d = defaultdict(int)
for i, A in enumerate(As, start=1):
    d[i] = A

B = 1 << M

queries = []


def shift(x, i):
    queries.append((1, x, i))
    d[x] = (d[i] << 1) % B


def nand(x, i, j):
    queries.append((2, x, i, j))
    d[x] = (~(d[i] & d[j])) % B


def or_(x, i, j):
    nand(TMP1, i, i)
    nand(TMP2, j, j)
    nand(x, TMP1, TMP2)


ZERO = 10 ** 8
N_ONE = ZERO - 1
nand(N_ONE, ZERO, ZERO)
N_TWO = N_ONE - 1
shift(N_TWO, N_ONE)
ONE = N_TWO - 1
nand(ONE, N_TWO, N_TWO)

# print(d[ZERO])
# print(d[N_ONE])
# print(d[N_TWO])
# print(d[ONE])

for b in reversed(range(M)):
    shift(0, 0)
    if (X >> b) & 1:
        or_(0, 0, ONE)

# print(d)

assert d[0] == X, '\n' + bin(d[0]) + '\n' + bin(X)

print(len(queries))
for q in queries:
    print(*q)
0