1994E - Wooden Game - CodeForces Solution


bitmasks greedy math sortings trees

Please click on ads to support us..

Python Code:

import math
import sys
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop,heapify
import gc
 
sys.setrecursionlimit(20000)
 
def getList(val=0):     if not val:return list(map(int,input().split()))
    else:return list(map(str,input().split()))
def getTuple(val=0):
    if not val:return map(int,input().split())
    return map(str,input().split())
def printList(arr,pri=False):
    if pri:print('ans',end=' ')
    for i in arr:print(i,end=' ')
    print()


def myCode():
    n = int(input())
    ans = []
    arr = [0 for i in range(20)]
    for __ in range(n):
        count = int(input())
        ddd = getList()
        ind = 0
        while count:
            b = count%2
            count = count>>1
            if b:arr[ind]+=1
            ind+=1
        for i in range(19,-1,-1):
        if arr[i]>1:
            ans += ['1']*(i+1)
            break
        elif arr[i]==1:
            ans.append('1')
        else:ans.append('0')
    print(int(''.join(ans),2))

        
for _ in range(int(input())):
    myCode()


Comments

Submit
0 Comments
More Questions

Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making