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: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    N=1<<n
    s=list(map(int,input().split()))
    s.sort(reverse=1)
    p=[s[0]]
    s[0]=INF
    for _ in range(n):
        p.sort(reverse=1)
        q=p[:]
        idx=0
        for i in q:
            while(idx!=N):
                j=s[idx]
                idx+=1
                if(i<=j): continue
                p.append(j)
                s[idx-1]=INF
                break
    print("Yes" if len(p)==N else "No")
resolve()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int,input().split()))
    a.sort()

    par = [a[-1]]
    rest = a[:-1]

    for _ in [0]*n:
        next_par = []
        next_rest = []

        for e in par:
            while True:
                if len(rest) == 0:
                    print('No')
                    exit()
                k = rest.pop()
                if k < e:
                    next_par.append(k)
                    break
                else:
                    next_rest.append(k)
        
        par += next_par
        par.sort(reverse = True)
        rest += next_rest[::-1]
    
    print('Yes')

if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
import heapq

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

maxn = (2**(n+1)) - 1
tree = [0] * maxn

s = sorted(s)

h = []
heapq.heappush(h, 0)
error = False

i = len(s) - 1
while i >= 0:
    count = 1
    while i >= 0 and s[i-1] == s[i]:
        count += 1
        i -= 1
    if len(h) < count:
        error = True
        break
    dh = []
    for _ in range(count):
        dh.append(heapq.heappop(h))
    for hi in dh:
        while hi*2+2 < maxn:
            heapq.heappush(h, hi*2+1)
            hi = hi*2+2
    i -= 1

if error:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
def b(bs, cs):
    d = set()
    bl, cl = len(bs), len(cs)
    bi, ci = 0, 0
    ncs = []
    while True:
      if bs[bi] > cs[ci]:
        bs.append(cs[ci])
        bi += 1
      else:
        ncs.append(cs[ci])
      ci += 1
      if bi == bl or ci == cl:
        break
    if len(bs) != 2 * bl:
      print("No")
      sys.exit()
    return bs, ncs + cs[ci:]

n=int(input())
xs = sorted(list(map(int,input().split())))[::-1]
bs, cs = xs[:1], xs[1:]
for _ in range(n):
    bs, cs = b(sorted(bs)[::-1], cs)

print("Yes")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc140/submissions/7397810

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):  # d: d-th trial is passed.
    j = 0  # j: skip num (already-generated or impossible-to-generate)
    for i in range(1 << d):  # Try split of i-th slim.
        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])  # b[i] > a[j]
        done[j] = True
    b.sort(reverse=True)
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import heapq
import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, S):
    bt = [0] * (2 ** (N + 1) - 1)
    M = len(bt)
    pq = []
    heapq.heappush(pq, (0, 0))

    S.sort(reverse=True)

    i = 0
    while i < len(S):
        v = S[i]
        j = i
        while j < len(S) and v == S[j]:
            j += 1
        c = j - i
        i = j

        if len(pq) < c:
            return False

        pl = [heapq.heappop(pq) for _ in range(c)]
        for level, idx in pl:
            ll = level
            while True:
                assert bt[idx] == 0
                bt[idx] = v
                s = 2 * idx + 1
                t = s + 1
                if s >= M:
                    break
                idx = s
                ll += 1
                heapq.heappush(pq, (ll, t))

    return True


def main():
    N = int(inp())
    S = [int(e) for e in inp().split()]
    print('Yes' if solve(N, S) else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 参考: https://atcoder.jp/contests/abc140/submissions/7402925
# できるだけ大きいスライムを貪欲に生んでいく
# 自力コードはTLEのためmaspyさんのコードを参考にした

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys


def solve(N, S):
    S = sorted(S)
    used = [S[-1]]
    unused = S[:-1]
    for _ in range(N):
        next_used = []
        next_unused = []
        for p in used[::-1]:
            while unused:
                x = unused.pop()
                if x < p:
                    next_used.append(x)
                    break
                else:
                    next_unused.append(x)
                    continue
        used += next_used
        used.sort()
        unused = unused + next_unused[::-1]
    
    return len(used) == (2**N)


N = int(input())
S = list(map(int, input().split()))
print("Yes" if solve(N, S) else "No")

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=i2()
m=10**9+1
s.sort(reverse=True)
x=[s[0]]
s[0]=m
a="Yes"
for i in range(n):
 y=[]
 k=0
 for j in range(len(s)):
   if k>=len(x):
      break
   if s[j]<x[k]:
     y.append(s[j])
     s[j]=m
     k+=1
 x+=y
 x.sort(reverse=True)
if k==(1<<(n-1)):
   print("Yes")
else:
   print("No")

Submission status: Accepted

Solution code:
N = int(input())
S = [int(i) for i in input().split()]

def solve() :
    S.sort()
    par = [S.pop()]
    rst = S
    for _ in range(N) :
        n_par = []
        n_rst = []
        
        for p in par[::-1] :
            flg = True
            while rst :
                if rst[-1] < p :
                    n_par.append(rst.pop())
                    flg = False
                    break
                else :
                    n_rst.append(rst.pop())
            if flg :
                return 'No'
                
        par += n_par
        par.sort()
        rst += n_rst
        rst.sort()
            
    return 'Yes'
    
print(solve())

Submission status: Accepted

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

    s = sorted(s)[::-1]

    slimes = [s[0]]
    s = s[1:]

    for i in range(n):
        make_slimes = []
        rest_slimes = []
        make_idx = 0
        for j in range(2 ** i):
            for tmp_make_idx in range(make_idx, len(s)):
                if slimes[j] > s[tmp_make_idx]:
                    make_slimes.append(s[tmp_make_idx])
                    break
                else:
                    rest_slimes.append(s[tmp_make_idx])
            make_idx = tmp_make_idx + 1
        rest_slimes += s[make_idx:]
        if len(make_slimes) < 2 ** i:
            print("No")
            return
        slimes += make_slimes
        s = rest_slimes
        slimes = sorted(slimes)[::-1]
        s = sorted(s)[::-1]
    print("Yes")


main()

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))
rest = sorted(s)
parent = [rest.pop()]

for _ in range(n):
    next_parent = []
    next_rest = []
    for i in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < i:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest += next_rest
    rest.sort()

if len(parent) == 2**n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
parent = [a[-1]]
rest = a[:-1]

for _ in range(n):
    next_parent = []
    next_rest = []
    for i in parent[::-1]:
        while(rest):
            x = rest.pop()
            if x < i:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    next_rest.reverse()
    rest += next_rest

if len(parent) == 2**n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

used = [s[0]]
unused = s[1:]
for i in range(n):
    nxt_used = []
    nxt_unused = []
    left = 0
    #print(used, unused)
    for j in used:
        while left < len(unused) and unused[left] >= j:
            nxt_unused.append(unused[left])
            left += 1
        if left == len(unused):
            print("No")
            exit()
        nxt_used.append(j)
        nxt_used.append(unused[left])
        left += 1
    nxt_unused += unused[left:]
    nxt_unused.sort(reverse=True)
    nxt_used.sort(reverse=True)
    used = nxt_used
    unused = nxt_unused
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
parent = [a[-1]]
rest = a[:-1]
for _ in range(n):
    next_parent = []
    next_rest = []
    for p in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < p:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest = rest + next_rest[::-1]

if len(parent) == 2**n:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:

def f_f():
    n, *s = map(int, open(0).read().split())
    s.sort()
    ps, next_ps, cs = [s.pop()], [], []
    for _ in range(n):
        for p in ps:
            while s:
                c = s.pop()
                if p>c:
                    next_ps.append(c)
                    break
                else:
                    cs.append(c)
        s, ps, next_ps, cs = s+cs[::-1], sorted(ps+next_ps, reverse=True), [], []

    print("No" if s else "Yes")

if __name__ == "__main__":
    f_f()

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
from collections import defaultdict
from sys import stderr
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return
def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S)
    exist = [S.pop()]
    debug(S)
    debug(exist)
    for i in range(N):
        next_exist = []
        next_s = []
        for p in exist[::-1]:
            while S:
                x = S.pop()
                if x < p:
                    next_exist.append(x)
                    break
                else:
                    next_s.append(x)
        exist += next_exist
        exist.sort()
        S += next_s[::-1]

    if len(exist) == 2**N:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

big =  [a[-1]]
rest = a[:-1]


for i in range(n):
    not_yet = []
    count = 0
    for b in big:
        if count==2**i:
            break
        while rest:
            r = rest.pop()
            if r < b:
                big.append(r)
                count += 1
                break
            not_yet.append(r)
    big.sort(reverse=True)
    rest += not_yet[::-1]
print("Yes" if len(rest)==0 else "No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)

key_num = len(cnt.keys())
rank = [0] * key_num 
keys = list(cnt.keys())
keys.sort(reverse=True)
for i, key in enumerate(keys):
    rank[i] = cnt[key]
cur = [0] * key_num 
cur[0] = 1
for i in range(n):
    tmp = cur[:]
    free = 0
    for j in range(key_num):
        if rank[j] > cur[j] and free > 0:
            if cur[j] + free > rank[j]:
                free -= rank[j] - cur[j]
                cur[j] = rank[j]
            else:
                cur[j] += free
                free = 0
        free += tmp[j] 
if sum(cur) == 2**n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

s.sort()

p = [s[-1]]
h = s[:-1]
for i in range(n):
    t = []
    o = []
    for j in p:

        while len(h):
            if h[-1] < j:
                o.append(h.pop())
                break
            t.append(h.pop())

    h.extend(t)
    p.extend(o)
    p.sort(reverse=True)
    h.sort()

print("Yes" if len(h) == 0 else "No")

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(n**3)
    return

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return

#D
def D():
    n,k = LI()
    a = S()
    ans = 0
    for i in range(n-1):
        if a[i] == a[i+1]:
            ans += 1
    print(min(n-1,ans+2*k))
    return

#E
def E():
    def add(i):
        while i <= n:
            bit[i] += 1
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    p = LI()
    r = [0]*n
    bit = [0]*(n+1)
    for i in range(n)[::-1]:
        r[i] = (n-i-1)-sum(p[i])
        add(p[i])
    print(r)
    l = [0]*n
    bit = [0]*(n+1)
    for i in range(n):
        l[i] = i-sum(p[i])
        add(p[i])
    print(l)

    return

#F
def F():
    n = I()
    s = LI()
    s.sort()
    s = s[::-1]
    m = 1<<n
    f = [-1]*m
    f[0] = 0
    for i in range(n):
        k = 0
        l = 0
        for j in range(1<<i):
            while f[k] != i:
                k += 1
            while f[l] >= i or s[k] <= s[l]:
                l += 1
                if l == m:
                    print("No")
                    return
            f[l] = i+1
            k += 1
        for j in range(m):
            if f[j] >= 0:
                f[j] = i+1
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    F()

Submission status: Accepted

Solution code:
import sys
N = int(input())
S = sorted(list(map(int, input().split())))
parent = [S[-1]]
rest = S[:-1]
for i in range(N):
    next_generation = []
    next_rest = []
    for p in parent[::-1]:
        while True:
            if len(rest) == 0:
                print('No')
                sys.exit()
            q = rest.pop()
            if p>q:
                next_generation.append(q)
                break
            else:
                next_rest.append(q)
    parent+=next_generation
    parent.sort()
    rest += next_rest
    rest.sort()
print('Yes')

Submission status: Accepted

Solution code:
def main():
    inf = 10 ** 9 + 5
    n = int(input())
    n2 = 2 ** n
    s = list(map(int, input().split()))
    s.sort(reverse=True)
    # print(s)
    pp = [s[0]]
    s[0] = inf
    for _ in range(n):
        pp.sort()
        i = 1
        np = pp[:]
        while pp:
            p = pp.pop()
            while 1:
                if s[i] < p:
                    np.append(s[i])
                    s[i] = inf
                    break
                else:
                    i += 1
                if i == n2:
                    print("No")
                    exit()
        pp = np
    print("Yes")

main()

Submission status: Accepted

Solution code:
N = int(input())
N2 = 1 << N

S = sorted([int(x) for x in input().split()])

s = []
s.append(S[-1])
S[-1] = -1

flag = True
for i in range(N):
    p = sorted([x for x in s])

    Si = N2 - 1
    while len(p) > 0 and Si >= 0:
        if S[Si] == -1:
            Si -= 1
            continue

        if S[Si] < p[-1]:
            s.append(S[Si])
            del p[-1]
            S[Si] = -1
        
        Si -= 1
    
    if len(p) > 0:
        flag = False

print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
import bisect

n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    global s

    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        k = len(s)
        dropped = set()
        # print(parents)
        for p in parents:
            oldK = k
            k = bisect.bisect(s, p - 1, 0, k) - 1
            # print("Old", oldK, k, s[k], p)
            if k == -1:
                print("No")
                exit(0)

            newparents.append(s[k])
            dropped.add(k)
        s = [x for i, x in enumerate(s) if i not in dropped]
        parents = sorted(newparents, reverse=True)

    # print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()

Submission status: Accepted

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

def main():
    N = int(input())
    s = sorted(list(map(int, input().strip().split())), reverse=True)
    check = [False] * (2**N)
    now = []
    now.append([s[0], 1])
    check[0] = True
    ok = True
    for i in range(N):
        next_ = []
        tmp = 0
        for j in range(len(now)):
            hp, start = now[j]
            start = max(start, tmp)
            ok = False
            for k in range(start, 2**N):
                if s[k] < hp and not check[k]:
                    tmp = k+1
                    now[j][1] = k+1
                    check[k] = True
                    next_.append([s[k], k+1])
                    ok = True
                    break
            if not ok:
                break
        now += next_
        now = sorted(now, reverse=True)
        if not ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    N = int(input())
    s = sorted(list(map(int, input().strip().split())), reverse=True)
    check = [False] * (2**N)
    now = []
    now.append([s[0], 1])
    check[0] = True
    ok = True
    for i in range(N):
        next_ = []
        tmp = 0
        for j in range(len(now)):
            hp, start = now[j]
            start = max(start, tmp)
            ok = False
            for k in range(start, 2**N):
                if s[k] < hp and not check[k]:
                    tmp = k+1
                    now[j][1] = k+1
                    check[k] = True
                    next_.append([s[k], k+1])
                    ok = True
                    break
            if not ok:
                break
        now += next_
        now = sorted(now, reverse=True)
        if not ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(n,S):
    Used=[False]*len(S)
    Cur=[]
    Cur.append(S[0])
    Used[0]=True
    for _ in range(n):
        idx=0
        num=len(Cur)
        for i,s in enumerate(S):
            if (not Used[i]) and s<Cur[idx]:
                Cur.append(s)
                idx+=1
                Used[i]=True
                if idx==num:
                    break
        else:
            return 'No'
        Cur.sort(reverse=True)
    return 'Yes'

n=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)
print(solve(n,S))

Submission status: Accepted

Solution code:
import sys,bisect as bs,collections as cl
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

p = l()

p.sort(reverse = True)

ms = p[0]
s = [p[0]]

for i in range(n):
    count = 0
    local = 0
    s.sort(reverse = True)
    while count < 2**i:
        if local >= 2**n:
            print("No")
            exit()
        if s[count] > p[local]:
            s.append(p[local])
            p[local] = ms
            count += 1
        local += 1
print("Yes")

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 解説AC
N = int(sys.stdin.readline())
S = list(map(int, sys.stdin.readline().split()))


def solve():
    counts = Counter(S)
    nums = list(sorted(counts.keys(), reverse=True))
    if counts[nums[0]] > 1:
        return False

    # 木の深さをもって深いやつから使っていく
    trees = [-i for i in range(1, N + 1)]
    heapq.heapify(trees)

    for n in nums[1:]:
        cnt = counts[n]
        if cnt > len(trees):
            return False
        uses = []
        for _ in range(cnt):
            t = -heapq.heappop(trees)
            uses.append(t)
        # 使ったら t-1 個の木に分解する
        for t in uses:
            for i in range(1, t):
                heapq.heappush(trees, -i)
    return True


if solve():
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

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

    g = [S.pop(-1)]

    for gen in range(N):
        tmp = []
        for p in g[:2**gen]:
            while S:
                s = S.pop(-1)
                if p > s:
                    g.append(s)
                    break
                else:
                    tmp.append(s)
            else:
                print('No')
                sys.exit()
        S.extend(tmp[::-1])
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

    g = [S.pop(-1)]

    for _ in range(N):
        tmp = []
        lg = len(g)
        for p in g[:lg]:
            while S:
                s = S.pop(-1)
                if p > s:
                    g.append(s)
                    break
                else:
                    tmp.append(s)
            else:
                print('No')
                sys.exit()
        S.extend(tmp[::-1])
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def solve_f(n, s_list):
    res = 'Yes'
    stage = 0
    s_list_s = sorted(s_list)
    length = len(s_list_s)
    resolved = [0] * length
    resolved[-1] = 1

    for i in range(n):
        parents = [s_list_s[k] for k in range(length) if resolved[k]]
        for j in range(length - 1, -1, -1):
            if parents[-1] > s_list_s[j] and resolved[j] == 0:
                resolved[j] = 1
                _ = parents.pop()
            if len(parents) == 0:
                break
        if len(parents) > 0:
            res = "No"
            break

    return res


def main():
    n = int(input())
    s_list = list(map(int, input().split()))
    print(solve_f(n, s_list))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

S.sort()

parent = [S.pop()]
rest = S
for _ in range(N):
	n_parent = []
	n_rest = []

	for p in parent[::-1]:
		while rest:
			x = rest.pop()
			if x < p:
				n_parent.append(x)
				break
			else:
				n_rest.append(x)
	parent += n_parent
	parent.sort()
	rest = rest + n_rest[::-1]

if len(parent) == (2**N):
	print("Yes")
else:
	print('No')

Submission status: Accepted

Solution code:
import sys

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

    g = [S.pop(-1)]

    for _ in range(N):
        c = []
        tmp = []
        for p in g:
            while S:
                s = S.pop(-1)
                if p > s:
                    c.append(s)
                    break
                else:
                    tmp.append(s)
            else:
                print('No')
                sys.exit()
        S.extend(tmp[::-1])
        g.extend(c)
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
## 他の方と処理内容がほぼ同じなのに何でTLEになるか分からないので、他の方のコードでテスト
N = int(input())
a = list(map(int,input().split(' ')))
a.sort()
    

fathers = [a.pop()]
for _ in range(N):
    sons = list()
    b = list()
    
    for father in fathers:
        while a:
            x = a.pop()
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = a + b[::-1]
    fathers.extend(sons)
    fathers.sort(reverse = True)
    
    
    
if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#F問題
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse=True)
visit = [0]*(2**N)
visit[0] = 1
used = [S[0]]

flag = 0
for i in range(N):
    add = used[::-1]
    k = 0
    for u in used:
        while k < 2**N:
            if visit[k] == 0 and S[k] < u:
                visit[k] = 1
                add.append(S[k])
                break
            k+=1
        if k >= 2**N:
            print("No")
            flag = 1
            break
    if flag == 1:
        break
    
    used = add[::-1]
    used.sort(reverse=True)
    
if flag == 0:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])

def main():
    N = I()
    S = sorted(LI(),reverse=True)

    flag = [True]*len(S)
    cur = []
    cur.append(S[0])
    flag[0] = False

    for i in range(N):
        j = 0
        jM = len(cur)
        for k in range(len(S)):
            if flag[k] and S[k]<cur[j]:
                cur.append(S[k])
                j+=1
                flag[k] = False
                if j==jM:
                  break
        else:
            return("No")
        cur.sort(reverse=True)
    return("Yes")

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])


def main():
    N = I()
    S = sorted(LI(),reverse=True)

    flag = [True]*len(S)

    cur = []
    nxt = []
    cur.append(S[0])
    nxt.append(S[0])
    
    flag[0] = False

    for i in range(N):
        j = 0
        for k in range(len(S)):
            if flag[k] and S[k]<cur[j]:
                nxt.append(S[k])
                j+=1
                flag[k] = False
                if j==len(cur):
                  break
        else:
            return("No")
        nxt.sort(reverse=True)
        cur = [x for x in nxt]
    return("Yes")

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])


def main():
    N = I()
    S = sorted(LI(),reverse=True)

    flag = [True]*len(S)

    cur = []
    nxt = []
    cur.append(S[0])
    nxt.append(S[0])
    
    flag[0] = False

    for i in range(N):
        j = 0
        for k in range(len(S)):
            if j >= len(cur):
                break
            elif flag[k] and S[k]<cur[j]:
                nxt.append(S[k])
                j+=1
                flag[k] = False
        if len(cur) != j:
            return("No")
        nxt.sort(reverse=True)
        cur = [x for x in nxt]
    return("Yes")

if __name__ == "__main__":
    print(main())