Problem:


Score : 600 points

Problem Statement

We have one slime.

You can set the health of this slime to any integer value of your choice.

A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.

Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.

Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.

Constraints

All values in input are integers.

1 \leq N \leq 18

1 \leq S_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
S_1 S_2 ... S_{2^N}

Output

If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.

Sample Input 1

2
4 2 3 1

Sample Output 1

Yes

We will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.

First, set the health of the first slime to 4.

By letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.

Then, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.

Sample Input 2

2
1 2 3 1

Sample Output 2

Yes

S may contain multiple instances of the same integer.

Sample Input 3

1
1 1

Sample Output 3

No

Sample Input 4

5
4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3

Sample Output 4

No



Sample input:
2
4 2 3 1


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse=True)
flag = False
for i in range(1,N):
    j = 2**i
    jj = j**2
    L = S[:j]
    R = S[j:jj]
    for j in range(len(L)):
        if L[j] <= R[j]:
            flag = True
            break
    if flag:
        break

if flag:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
f = [max(a)]
for _ in range(n):
    f += list(map(lambda x:x-1,f))
a.sort()
f.sort()
for i in range(2**n):
    if a[i] > f[i]:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
s.sort(reverse = True)
flag = True
test = [s.pop(0)]
for i in range(n):
    for j in range(2 ** i):
        if test[j] == s[0]:
            flag = False
            break
        else:
            test.append(s.pop(0))
    if flag == False:
        break
if flag == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(map(int,input().split()))
ans = "Yes"
hp = max(S)
cnt = 0
for i in range(n):
    cnt = sum( i >= hp-1 for i in S)
    if cnt >= 2**(i+1):
        ans = "No"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 262145)))

s = sorted(s, reverse=True)

def merge(x, y):

    i = 0
    j = 0

    new = []
    k = 0
    l = 0
    while k < len(x):
        if x[k] > y[l]:
            k += 1
            l += 1
        else:
            print("No")
            exit(0)

        if x[i] > y[j]:
            new.append(x[i])
            i += 1
        else:
            new.append(y[j])
            j += 1

    new.extend(x[i:])
    new.extend(y[j:])
    return new

slimes = [s[0]]
s = s[1:]
for i in range(n):
    newslimes = []
    m = len(slimes)
    slimes = merge(slimes, s[:m])
    # print(slimes)
    s = s[m:]
    # print(len(slimes), len(s))

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

    
if __name__ == '__main__':
    N = int(input())
    S = InputToInt()
    S.sort(reverse=True)

    if S[0] == S[1]:
        print('No')
        sys.exit()
    
    for i in range(1, N):
        for j in range(2**(i-1)):
            if S[2**(i-1)+j] > S[2**(i-1)*3+j]:
                pass
            else:
                print('No')
                sys.exit()
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)
nCr = {}

def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n=int(input())
slist = list(map(int, input().split()))

if len(slist)==2**n:
    slist = sorted(slist, reverse=True)
    #print(slist)
    dekai=slist[0]
    now=0
    now2=dekai
    swit=1
    for i in range(n):
        now+=cmb(n, i)
        if slist[now]>now2-1:
            swit=0
        now2=slist[now]
    if swit==1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import queue

n = int(input())
m = pow(2, n)
a = list(map(int, input().split()))
a = list(reversed(sorted(a)))
q = queue.Queue()
b = []

q.put([a[0], n])
b.append(a[0])

while not q.empty():
    top = q.get()
    while top[1]:
        q.put([top[0] - 1, top[1] - 1])
        b.append(top[0] - 1)
        top[1] -= 1

for i, j in zip(a, b):
    if i > j:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse=True)
a = 1
for _ in range(n):
    for i, j in zip(s[:a], s[a:2 * a]):
        if i == j:
            print("No")
            exit()
    a *= 2
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [int(x) for x in input().split()]
ans = 1
S = sorted(S, reverse=True)
for i in range(N):
    for j in range(2 ** i):
        if S[j] == S[j + 2 ** i]:
            ans = 0
            break
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
from heapq import heappush, heappop


def solve(n, sss):
    keys = [-1] + sorted(sss.keys())
    if sss[keys[-1]] != 1:
        return False
    m = keys.pop()
    q = [(-m, n)]
    k = keys[-1]
    while k != -1:
        s, r = heappop(q)
        s = -s
        if r > 0 and k >= s:
            return False
        for i in range(r):
            heappush(q, (-k, r - i - 1))
            sss[k] -= 1
            if sss[k] == 0:
                keys.pop()
                k = keys[-1]
        # print(s, r, q, keys, sss)
    return True


n = int(input())
sss = Counter(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
SS = inpl()
SS.sort(reverse=True)

def solve1():
    for t in range(N):
        now = SS[0]
        itr = 1
        for i in range(N,t,-1):
            if now > SS[itr]:
                #print(now,SS[itr])
                now = SS[itr]
                itr += i
                continue
            else:
                return False
    return True

def solve2():
    now = [SS[0]]
    for t in range(1,N+1):
        itr = 0
        for i in range(2**(t-1),2**t):
            if now[itr] > SS[i]:
                now.append(SS[i])
            else:
                return False
            itr += 1
    return True

if solve1() or solve2():
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def count(k):
    return bin(k).count("1")
N=int(input())
S=sorted([int(i) for i in input().split()],reverse=True)
T=sorted([(i,count(i)) for i in range(2**N)],key=lambda x:x[1])
U=[0 for i in range(2**N)]
for i in range(2**N):
    U[T[i][0]]=S[i]
for i in range(N):
    for j in range(2**i):
        if U[j]==U[j+2**i]:
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
S = list(map(int, input().split()))

S.sort(reverse=True)

for bit in range(N):
	for i in range(2**bit):
		#print(i + 2**bit, i, bit)
		if S[i] == S[i + 2**bit]:
			print("No")
			exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
s.reverse()
t = []
last = s[0]
cnt = 1
for i in range(1,2**n):
  if last == s[i]:
    cnt += 1
  else:
    t.append([last,cnt])
    last = s[i]
    cnt = 1
t.append([last,cnt])
#print(s)
#print(t)
com = [1]
for i in range(n):
  com.append( com[-1] * (n-i) // (i+1) )
#print(com)
king = s[0]
here = 0
rest = 0
for k in range(n+1):
  rest += com[k]
  rest -= t[k][1]
  if rest < 0:
      print('No')
      break
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
SS = inpl()
SS.sort(reverse=True)

for t in range(N):
    now = SS[0]
    itr = 1
    for i in range(N,t,-1):
        if now > SS[itr]:
            #print(now,SS[itr])
            now = SS[itr]
            itr += i
            continue
        else:
            print('No')
            exit()


print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
xs = sorted(list(map(int, input().split())))

while True:
    b = None
    c = 1
    nxs = []
    for x in xs:
        if b == None:
            b = x
            continue
        if x == b:
            c += 1
            continue
        if c > 0:
            nxs.append(x)
            c -= 1
        else:
            c += 1
        b = x
    xs = nxs
    if c != 0:
        r = "No"
        break
    if len(xs) == 1:
        r = "Yes"
        break

print(r)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

poi = [0] * (1<<n)
poi[0] = n
p = 1
for i in range(1<<n):
    if poi[i] > 0 and a[i] == a[p]:
        print("No")
        sys.exit(0)
    for k in range(poi[i]):
        poi[p] = poi[i] - k - 1
        p += 1
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse=True)
a = s[0]
b = 1
i = 0
while True:
    while i < 2 ** n and s[i] == a:
        i += 1
    if i - 1 >= b:
        print("No")
        exit()
    if i >= 2 ** n:
        print("Yes")
        exit()
    a = s[i]
    b = max(b - i, 0) + i * 2

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = sorted(map(int,input().split()),reverse=True)

usenum = 1
USE= [0]*(1<<N)
USE[0] = N

for i in range(N):

    while USE[i]>=1:
        if A[usenum]>=A[i]:
            print("No")
            sys.exit()
        else:
            USE[usenum]=USE[i]-1
            USE[i]-=1
            usenum+=1


print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    S = lmi()
    S.sort()
    # print(S)
    s = [pow(2, i)for i in range(N - 1, -1, -1)]
    last = 0
    # print(s)
    for i in range(N):
        if S[last] == S[last + s[i]]:
            print("No")
            sys.exit()
        # print(last)
        last += s[i]
    print("Yes")
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
s.reverse()
t = []
last = s[0]
cnt = 1
for i in range(1,2**n):
  if last == s[i]:
    cnt += 1
  else:
    t.append([last,cnt])
    last = s[i]
    cnt = 1
t.append([last,cnt])
#print(s)
#print(t)
com = [1]
for i in range(n):
  com.append( com[-1] * (n-i) // (i+1) )
#print(com)
king = s[0]
here = 0
rest = 0
for k in range(n+1):
  rest += com[k]
  if t[here][0] == king-k:
    rest -= t[here][1]
    here += 1
  if rest < 0:
      print('No')
      break
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque


def solve(n, sss):
    keys = [-1] + sorted(sss.keys())
    m = keys.pop()
    if sss[m] != 1:
        return False
    q = deque([m])
    k = keys[-1]
    while k != -1:
        s = q.popleft()
        if k >= s:
            return False
        q.append(k)
        sss[k] -= 1
        if sss[k] == 0:
            keys.pop()
            k = keys[-1]
    return True


n = int(input())
sss = Counter(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 262145)))

s = sorted(s, reverse=True)

def merge(x, y):

    i = 0
    j = 0

    new = []
    while i < len(x) and j < len(y):
        if x[i] > y[j]:
            new.append(x[i])
            i += 1
        else:
            print("No")
            exit(0)
            new.append(y[j])
            j += 1
    new.extend(x[i:])
    new.extend(y[j:])
    return new

# print(len(s))
slimes = [s[0]]
s.pop(0)
for i in range(n):
    newslimes = []
    m = len(slimes)
    slimes = merge(slimes, s[:m])
    s = s[m:]
    # print(len(slimes), len(s))

print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)

M=S[0]
m=1
CNT=1
cnt=1

for i in range(1,2**N):
    if S[i]==M:
        if CNT>cnt:
            cnt+=1
        elif CNT==cnt:
            print("No")
            exit()
    elif S[i]<M:
        cnt=1
        CNT+=1
        M=S[i]
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    for _ in range(N):
        sl = int(len(S) / 2)
        for s1,s2 in zip(S[:sl],S[sl:]):
            if s1 >= s2:
                print('No')
                sys.exit()
        S = S[sl:]

    print('Yes')

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
from heapq import heappush, heappop


def solve(n, sss):
    keys = [-1] + sorted(sss.keys())
    # print(sss)
    # print(keys)
    if sss[keys[-1]] != 1:
        return False
    m = keys.pop()
    q = [(-m, -n)]
    while q:
        s, r = heappop(q)
        s = -s
        r = -r
        k = keys[-1]
        if k >= s:
            return False
        for i in range(r):
            heappush(q, (-k, -(r - i - 1)))
            sss[k] -= 1
            if sss[k] == 0:
                keys.pop()
                k = keys[-1]
        # print(s, r, q)
    return True


n = int(input())
sss = Counter(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))

s.sort()
s.reverse()

for i in range(n):
    a = s[0:2**i]
    b = s[2**i:2**(i+1)]
    for j in range(len(a)):
        if b[j]>=a[j]:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

done = [False] * (1<<n)
b = [a[0]]
done[0] = True
for d in range(n):
    j = 0
    for i in range(1<<d):
        while j < 1<<n and (done[j] or b[i] <= a[j]):
            j += 1
        if j == 1<<n:
            print("No")
            sys.exit(0)
        b.append(a[j])
        done[j] = True
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

    
if __name__ == '__main__':
    N = int(input())
    S = InputToInt()
    S.sort(reverse=True)

    for i in range(N):
        if S[2**i-1] > S[2**i*2-1]:
            pass
        else:
            print('No')
            sys.exit()
    print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter
from heapq import heappush, heappop


def solve(n, sss):
    keys = [-1] + sorted(sss.keys())
    if sss[keys[-1]] != 1:
        return False
    m = keys.pop()
    q = [(-m, n)]
    while q:
        s, r = heappop(q)
        s = -s
        k = keys[-1]
        if k >= s:
            return False
        for i in range(r - 1):
            heappush(q, (-k, r - i - 1))
            sss[k] -= 1
            if sss[k] == 0:
                keys.pop()
                k = keys[-1]
    return True


n = int(input())
sss = Counter(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse=True)
a = s[0]
b = 1
i = 0
while True:
    while i < 2 ** n and s[i] == a:
        i += 1
    if i - 1 >= b:
        print("No")
        exit()
    if i >= 2 ** n:
        print("Yes")
        exit()
    a = s[i]
    b =i*2

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque


def solve(n, sss):
    keys = [-1] + sorted(sss.keys())
    if sss[keys[-1]] != 1:
        return False
    m = keys.pop()
    q = deque([(m, n)])
    while q:
        s, r = q.popleft()
        k = keys[-1]
        if k >= s:
            return False
        for i in range(r - 1):
            q.append((k, r - i - 1))
            sss[k] -= 1
            if sss[k] == 0:
                keys.pop()
                k = keys[-1]
    return True


n = int(input())
sss = Counter(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort(reverse=True)
l1=s[:1]
t=1
for i in range(n):
    l2=s[t:2*t]
    for j in range(t):
        if l2[j]==l1[j]:
            print("No")
            quit()
    l1+=l2
    t*=2
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

for d in range(n):
    for i in range(1<<d):
        if a[i] <= a[i+(1<<d)]:
            print("No")
            sys.exit(0)
print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
S=sorted([int(i) for i in input().split()],reverse=True)
for i in range(N):
    for j in range(2**i):
        if S[j]==S[j+2**i]:
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)

for i in range(N):
    k = 2**i
    for a,b in zip(P[:k], P[k:2*k]):
         if a<=b:
             print('No')
             exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
s = map(int,raw_input().split())
s = sorted(s,reverse=True)
win = True
for k in xrange(1,n+1):
	i = 0
	j = 2**(k-1)
	while i<2**(k-1):
		if s[i] <= s[j]:
			win = False
			break
		i += 1
		j += 1
	if not win:
		break
if win:
	print "Yes"
else:
	print "No"

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
SS = inpl()
SS.sort(reverse=True)

#print(SS)

now = [SS[0]]
for t in range(1,N+1):
    itr = 0
    for i in range(2**(t-1),2**t):
        if now[itr] > SS[i]:
            now.append(SS[i])
        else:
            print('No')
            exit()
        itr += 1
    #print(now)

print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse=True)
a = s[0]
b = 1
i = 0
for _ in range(20):
    while i < 2 ** n and s[i] == a:
        i += 1
    if i - 1 >= b:
        print("No")
        exit()
    if i >= 2 ** n:
        print("Yes")
        exit()
    a = s[i]
    b *= 2

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

for d in range(n):
    for i in range(1<<d):
        if a[i] <= a[i+1]:
            print("No")
            sys.exit(0)
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split(" ")))

s = sorted(s, reverse=True)

def merge(x, y):

    i = 0
    j = 0

    new = []
    while i < len(x) and j < len(y):
        if x[i] > y[j]:
            new.append(x[i])
            i += 1
        else:
            new.append(y[j])
            j += 1
    new.extend(x[i:])
    new.extend(y[j:])
    return new

slimes = [s[0]]
s.pop(0)
for i in range(n):
    newslimes = []
    for slime in slimes:
        if s[0] < slime:
            newslimes.append(s[0])
            s.pop(0)
        else:
            print("No")
            exit(0)

    slimes = merge(slimes, newslimes)

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split(" ")))

s = sorted(s, reverse=True)

slimes = [s[0]]
s.pop(0)
for i in range(n):
    newslimes = []
    for slime in slimes:
        newslimes.append(slime)
        if s[0] < slime:
            newslimes.append(s[0])
            s.pop(0)
        else:
            print("No")
            exit(0)
    slimes = sorted(newslimes, reverse=True)

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
S = sorted(map(int, input().split()), reverse=True)
L = [S[0]]
used = [False]*(1<<n)
used[0] = True
for i in range(n):
  T = []
  for l in L:
    for j, s in enumerate(S):
      if used[j]:
        continue
      if l > s:
        T.append(s)
        used[j] = True
        break
    else:
      print("No")
      exit()
  L += T
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
class MultisetBIT:
    """
    最大値が小さい数について、その重複を許した集合を管理する。
    最大値 maxvalue を受け取り、[0, maxvalue] を管理する。
    counter は辞書型かリスト型で、counter[i] が i の個数を持つことを仮定する。
    counter が与えられなかった場合は、全て個数 0 で初期化される。
    基本的に閉区間で管理する。
    内部では受け取った数を +1 したものをindexとして持っているので注意。
    """

    __slots__ = ["n", "k", "data"]

    def __init__(self, maxvalue, counter = None):
        self.n = maxvalue + 1
        self.k = 1 << ((self.n + 1).bit_length() - 1)
        self.data = [0] * (self.n + 1)
        if counter is not None:
            self.update(counter)
        
    def update(self, counter):
        """
        counter を受け取って、それを反映させる。
        counter は辞書型かリスト型で、counter[i] が i の個数を持つことを仮定する。(0 <= i <= maxvalue)
        計算量は、n を要素の最大値として、 O(n) となる。
        """
        if isinstance(counter, list):
            self.data = [0] + counter + [0] * (self.n - len(counter))
        else:
            self.data = [0] * (self.n + 1)
            for k, v in counter.items():
                self.data[k + 1] = v
        for i in range(1, self.n + 1):
            if i + (i & -i) <= self.n:
                self.data[i + (i & -i)] += self.data[i]

    def add(self, value):
        """
        与えられた引数 value (0 <= value <= maxvalue) を Multiset に加える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        value += 1
        while value <= self.n:
            self.data[value] += 1
            value += value & -value

    def pop(self, value):
        """
        Multiset から与えられた引数 value (0 <= value <= maxvalue) を取り除く。
        与えられた引数が Multiset に入っているかのチェックは行わなず、
        単にその個数を 1 減らすだけなので注意。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        value += 1
        while value <= self.n:
            self.data[value] -= 1
            value += value & -value

    def count_le(self, value):
        """
        Multiset 内の要素 elem のうち、0 <= elem <= value を満たすものを数える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        value は value <= maxvalue を満たす必要がある。
        """
        value += 1
        ret = 0
        while value > 0:
            ret += self.data[value]
            value -= value & -value
        return ret

    def count(self, first, last):
        """
        Multiset 内の要素 elem のうち、first <= elem <= last を満たすものを数える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        0 <= first <= last <= max_value が必要。
        """
        last += 1
        ret = 0
        while first < last:
            ret += self.data[last]
            last -= last & -last
        while last < first:
            ret -= self.data[first]
            first -= first & -first
        return ret

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.count(index.start, index.stop - 1)
        else:
            return self.count(index, index)

    def bisect(self, count):
        """
        Multiset 内の要素 elem のうち、count <= count_le(elem) を満たす最小のelemを返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        ret = 0
        k = self.k
        while k > 0:
            if ret + k <= self.n and self.data[ret + k] < count:
                count -= self.data[ret + k]
                ret += k
            k //= 2
        return ret

    def lower_bound(self, value):
        """
        Multiset 内の要素 elem のうち、value <= elem を満たす最小のelemを返す。
        そのような elem が存在しない場合は maxvalue + 1 を返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        return self.bisect(self.count_le(value - 1) + 1)

    def upper_bound(self, value):
        """
        Multiset 内の要素 elem のうち、value < elem を満たす最小のelemを返す。
        そのような elem が存在しない場合は maxvalue + 1 を返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        return self.bisect(self.count_le(value) + 1)


N = int(input())
S_list = sorted(map(int, input().split()), reverse=True)

ans_tree = [0] * ((2 ** N) * 2)

ms = MultisetBIT((2 ** N) * 2)
ms.add(1)
for S in S_list:
    elem = ms.lower_bound(0)
    while elem != ((2 ** N) * 2 + 1) and ans_tree[elem // 2] == S:
        elem = ms.upper_bound(elem)
    
    if elem == ((2 ** N) * 2 + 1):
        print("No")
        exit()
    else:
        ms.pop(elem)
        ans_tree[elem] = S
        elem *= 2
        while elem < 2 ** N * 2:
            ans_tree[elem] = S
            ms.add(elem + 1)
            elem *= 2

print("Yes")
# print(ans_tree)

Submission status: Time Limit Exceeded

Solution code:
class BinaryIndexTree:  # 1-indexed
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


N = int(input())
A = list(map(int, input().split()))
atoi = {a: i+1 for i, a in enumerate(sorted(set(A)))}

bit = BinaryIndexTree(len(atoi) + 5)

for a in A:
    i = atoi[a]
    bit.add(i, 1)


slime = []

p = bit.lower_bound(1 << N)
slime.append(p)
bit.add(p, -1)

for _ in range(N):
    next_slime = []
    for s in slime:
        tot = bit.sum(s - 1)
        p = bit.lower_bound(tot)
        if p == 0:
            print("No")
            exit()
        next_slime.extend([s, p])
        bit.add(p, -1)
    slime = next_slime
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = [int(i) for i in ipt().split()]
    s.sort(reverse=True)
    hq = [1]
    num = [0]*(2**(n+1)+1)
    num[0] = 10**10
    nqi = []
    for i in s:
#        print(hq)
        while hq:
            qi = hpq.heappop(hq)
            if num[qi//2] == i:
                if not hq:
                    print("No")
                    exit()
                nqi.append(qi)
                continue
            ndi = qi*(2**(n-len(str(format(qi,"b")))+1))
            while ndi > qi:
                num[ndi] = i
                hpq.heappush(hq,(ndi//2)*2+1)
                ndi //= 2
            num[qi] = i
            while nqi:
                hpq.heappush(hq,nqi.pop())
            break
    print("Yes")



if __name__ == '__main__':
    main()