앞전의 이진수에서 1이 있는 자릿수를 계승하는 수열을 growing sequence라 하고
그렇지 않은 수열을 xor연산을 통해 growing sequence로 만들어 주는 수열을 Co-growing Sequence라 합니다.
전에 있는 값을 pivot으로 가져가야할 1의 위치를 저장하는 기준값으로 정하고 pivot에는 1이 있는데 현 수열의 값에는 없다면 Co-growing Sequence가 그만큼의 값을 가져가게끔 코드를 짰습니다.
import sys
input = sys.stdin.readline
for test in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
pivot = x[0]
y = [0] * n
for i in range(1, n):
l = len(bin(pivot)[2:])
for j in range(l):
k = (1 << j)
if pivot & k and not x[i] & k:
y[i] += k
pivot = x[i] ^ y[i]
print(*y)
'practivceAlgorithm > codeforce' 카테고리의 다른 글
[codeforce][Python] #719 A.Do Not Be Distracted! (0) | 2021.10.17 |
---|---|
[Codefroce][Python] div.3 #731 - E. Air Conditioners (0) | 2021.10.03 |
[Codefroce][Python] div.3 #731 - C. Pair Programming (0) | 2021.10.03 |
[Codefroce][Python] div.3 #731 - B. Alphabetical Strings (0) | 2021.10.03 |
[Codefroce][Python] div.3 #731 - A. Shortest Path with Obstacle (0) | 2021.10.03 |