結果

問題 No.1589 Bit Vector
ユーザー chineristACchineristAC
提出日時 2021-07-09 01:14:51
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,358 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 78,740 KB
最終ジャッジ日時 2023-09-14 06:14:47
合計ジャッジ時間 6,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
74,360 KB
testcase_01 AC 107 ms
74,208 KB
testcase_02 AC 114 ms
74,504 KB
testcase_03 AC 106 ms
74,772 KB
testcase_04 AC 112 ms
74,592 KB
testcase_05 AC 111 ms
74,724 KB
testcase_06 AC 107 ms
74,384 KB
testcase_07 AC 107 ms
74,432 KB
testcase_08 AC 111 ms
74,692 KB
testcase_09 AC 106 ms
74,480 KB
testcase_10 AC 106 ms
74,540 KB
testcase_11 AC 106 ms
74,416 KB
testcase_12 AC 108 ms
74,596 KB
testcase_13 AC 107 ms
74,528 KB
testcase_14 AC 109 ms
74,256 KB
testcase_15 AC 112 ms
74,504 KB
testcase_16 AC 111 ms
74,476 KB
testcase_17 AC 111 ms
74,392 KB
testcase_18 AC 110 ms
74,208 KB
testcase_19 AC 113 ms
74,244 KB
testcase_20 AC 116 ms
78,656 KB
testcase_21 AC 115 ms
78,580 KB
testcase_22 AC 117 ms
78,256 KB
testcase_23 AC 115 ms
78,260 KB
testcase_24 AC 118 ms
78,336 KB
testcase_25 AC 114 ms
78,740 KB
testcase_26 AC 117 ms
78,136 KB
testcase_27 AC 117 ms
78,320 KB
testcase_28 AC 113 ms
78,232 KB
testcase_29 AC 116 ms
78,604 KB
testcase_30 AC 114 ms
78,684 KB
testcase_31 AC 126 ms
78,708 KB
testcase_32 AC 118 ms
78,712 KB
testcase_33 AC 119 ms
78,636 KB
testcase_34 AC 112 ms
78,388 KB
testcase_35 AC 110 ms
74,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def update_ai_by_aj(i,j):
    res = ["UPD {} {}".format(i,1),"AND {} {} {}".format(i,i,j)]
    return res

def update_by_bool(b,i,j):
    """
    ・b:Trueならaiをajでupdate
    ・b,jは破壊してok
    """
    res = []
    res.append("AND {} {} {}".format(j,b,j))
    res.append("AND {} {} {}".format(b,b,i))
    res.append("XOR {} {} {}".format(i,i,j))
    res.append("XOR {} {} {}".format(i,i,b))
    return res

N,K = mi()

res = []

res.append("AND {} {} {}".format(N,0,1))
res.append("XOR {} {} {}".format(0,0,1))
res += update_ai_by_aj(1,N)
res.append("UPD {} {}".format(N,0))

up_memo = N
AND_regi = 2
for b in range(2,N):
    if b+1 == 1<<AND_regi:
        AND_regi += 1

    res.append("AND {} {} {}".format(up_memo,0,b))
    res.append("XOR {} {} {}".format(0,0,b))
    for i in range(1,AND_regi):
        res.append("AND {} {} {}".format(AND_regi,up_memo,i))
        res.append("XOR {} {} {}".format(i,up_memo,i))
        res += update_ai_by_aj(up_memo,AND_regi)

res.append("UPD {} {}".format(AND_regi,0))
res.append("UPD {} {}".format(N,0))

#res += ["debug"]

if N==2:
    if K==1:
        res.append("XOR {} {} {}".format(2,0,1))
    else:
        res += update_ai_by_aj(2,1)
else:
    assert AND_regi!=N
    for i in range(AND_regi):
        res.append("UPD {} {}".format(AND_regi,(K-1)>>i & 1))
        res.append("XOR {} {} {}".format(AND_regi,i,AND_regi))
        res += update_by_bool(AND_regi,N,i)
        res.append("UPD {} {}".format(AND_regi,0))

print(len(res))
print(*res,sep="\n")
#print(len(res))

"""
check = li()
A = [check[i] for i in range(N)] + [0]
flag = False
for s in res:
    op = [t for t in s.split()]
    if op[0]=="UPD":
        _,i,j = op
        i,j = int(i),int(j)
        A[i] = j
    elif op[0]=="AND":
        _,i,j,k = op
        print(i,j,k)
        i,j,k = int(i),int(j),int(k)
        A[i] = A[j]&A[k]
    elif op[0]=="XOR":
        _,i,j,k = op
        i,j,k = int(i),int(j),int(k)
        A[i] = A[j]^A[k]
    else:
        flag = True
        print(AND_regi)
    if flag:
        #print(A)

print(A)
print(A[N])
"""
0