Problem:


Score : 600 points

Problem Statement

Takahashi has N cards. The i-th of these cards has an integer A_i written on it.

Takahashi will choose an integer K, and then repeat the following operation some number of times:

Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)

For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Constraints

 1 \le N \le 3 \times 10^5 

 1 \le A_i \le N 

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print N integers.
The t-th (1 \le t \le N) of them should be the answer for the case K=t.

Sample Input 1

3
2 1 2

Sample Output 1

3
1
0

For K = 1, we can do the operation as follows:

Choose the first card to eat.

Choose the second card to eat.

Choose the third card to eat.

For K = 2, we can do the operation as follows:

Choose the first and second cards to eat.

For K = 3, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

5
2
1
1
1

Sample Input 3

4
1 3 3 3

Sample Output 3

4
1
0
0



Sample input:
3
2 1 2


Sample output:
3
1
0

Submission status: Time Limit Exceeded

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

#input
N = int(input())
A = list(map(int, input().split()))

from collections import Counter
import bisect
import numpy as np

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)
l = np.sort(l)
m = np.cumsum(l)
p = m[-1]

maximum_operation = [0] * N

ll = []
for x in range(1, N+1):
    a = bisect.bisect_left(l, x)
    if a == 0:
        b = M*x
        c = 0
    elif a >= M:
        b = 0
        c = p
    else:
        b = (M-a)*x
        c = m[a-1] 
    ll.append((b + c)/x)
ll = np.sort(ll)

for K in range(M):
    maximum_operation[K] = N - bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)

Submission status: Time Limit Exceeded

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

#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import Counter
import bisect
import numpy as np

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)
l.sort()
m = np.cumsum(l)
p = m[-1]

maximum_operation = [0] * N

ll = []
for x in range(1, N+1):
    a = bisect.bisect_left(l, x)
    if a == 0:
        b = M*x
        c = 0
    elif a >= M:
        b = 0
        c = p
    else:
        b = (M-a)*x
        c = m[a-1] 
    ll.append((b + c)/x)
ll.sort()

for K in range(M):
    maximum_operation[K] = N - bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)

Submission status: Time Limit Exceeded

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

n = int(input())
a = [int(item) for item in input().split()]
cnt = [0] * (n + 1)
for item in a:
    cnt[item] += 1
cnt.sort()
cumsum = [0] * (n + 2)
for i in range(n+1):
    cumsum[i+1] = cumsum[i] + cnt[i]

ans = []
for i in range(n):
    if cnt[i+1] == 0:
        ans.append(0)
        continue
    l = 0; r = n+1
    while r - l > 1:
        mid = (l + r) // 2
        index = bisect.bisect_left(cnt, mid) - 1
        if index <= i:
            l = mid
            continue
        num = index - i
        if mid * num <= cumsum[index + 1]:
            l = mid
        else:
            r = mid
    ans.append(l)

ans.reverse()
print("\n".join([str(item) for item in ans]))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
a = [int(item) for item in input().split()]
cnt = [0] * (n + 1)
for item in a:
    cnt[item] += 1
cnt.sort()
cumsum = [0] * (n + 2)
for i in range(n+1):
    cumsum[i+1] = cumsum[i] + cnt[i]

ans = []
for i in range(n):
    if cnt[i+1] == 0:
        ans.append(0)
        continue
    l = 0; r = n+1
    while r - l > 1:
        mid = (l + r) // 2
        index = bisect.bisect_left(cnt, mid) - 1
        if index <= i:
            l = mid
            continue
        num = index - i
        if mid * num <= cumsum[index + 1]:
            l = mid
        else:
            r = mid
    ans.append(l)

ans.reverse()
for item in ans:
    print(item)

Submission status: Time Limit Exceeded

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

#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import Counter
import bisect

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)

maximum_operation = [0] * N

ll = []
for x in reversed(range(1, N+1)):
    ll.append(sum([min(x, i) for i in l]) / x)

for K in range(M):
    maximum_operation[K] = N-bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
k=1
for i in range(n-1):
    if a[i]==a[i+1]:
        k+=1
    else:
        b.append(k)
        k=1
b.append(k)
b.sort(reverse=True)
print(n)
l=len(b)
for i in range(2,n+1):
    if l<i:
        print(0)
    else:
        c=[x for x in b]
        ans=0
        for j in range(n+1):
            if c[i-1]!=0:
                ans += c[i-1]
                for m in range(i):
                    c[m]-=c[i-1]
                c.sort(reverse=True)
            else:
                break
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
from copy import copy
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
k=1
for i in range(n-1):
    if a[i]==a[i+1]:
        k+=1
    else:
        b.append(k)
        k=1
b.append(k)
b.sort(reverse=True)
print(n)
l=len(b)
for i in range(2,n+1):
    if l<i:
        print(0)
    else:
        c=b.copy()
        ans=0
        for j in range(n+1):
            if c[i-1]!=0:
                ans += c[i-1]
                for m in range(i):
                    c[m]-=c[i-1]
                c.sort(reverse=True)
            else:
                break
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

# リストarrからx個の同じ長さの列を取り出す時の最大の長さ
# 発想: x個取り出す時、ある文字をx個より多く取り出して列に含むことはない
#       一方ある文字をその文字がある数よりも取り出して使うこともできない
#       つまり、min(arr.count(a), x)で、x個の同じ長さの列に使えるaの数がわかる
#       さらに、sum(min(arr.count(a),x))で、x個の同じ長さの列に使える文字の数がわかる
#       よって、sum(min(arr.count(a),x))//xで、x個の同じ長さの列の長さがわかる
#       発展的に、longest(arr,x)までの計算状況からlongest(arr,x+1)が計算できる
def longest(arr, x):    # legacy
    return sum(min(arr.count(a), x) for a in arr) // x


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

counter = collections.Counter(a)
nums = list(counter.values())
num_counter = collections.Counter(nums)
lastest_add = np.count_nonzero(nums)
building, longests = [0]*(n+1), [0]*(n+1)
for i in range(1, n+1):
    appended = building[i-1] + lastest_add
    building[i] = appended
    longests[i] = appended // i
    lastest_add -= num_counter[i]

for k in range(1, n+1):
    maxindexes = list(i for i, x in enumerate(longests) if x >= k)
    if maxindexes:
        print(maxindexes[-1])
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

# リストarrからx個の同じ長さの列を取り出す時の最大の長さ
# 発想: x個取り出す時、ある文字をx個より多く取り出して列に含むことはない
#       一方ある文字をその文字がある数よりも取り出して使うこともできない
#       つまり、min(arr.count(a), x)で、x個の同じ長さの列に使えるaの数がわかる
#       さらに、sum(min(arr.count(a),x))で、x個の同じ長さの列に使える文字の数がわかる
#       よって、sum(min(arr.count(a),x))//xで、x個の同じ長さの列の長さがわかる
#       発展的に、longest(arr,x)までの計算状況からlongest(arr,x+1)が計算できる
def longest(arr, x):    # legacy
    return sum(min(arr.count(a), x) for a in arr) // x


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

counter = collections.Counter(a)
nums = list(counter.values())
num_counter = collections.Counter(nums)
lastest_add = np.count_nonzero(nums)
building = [0]
longests = [0]
for i in range(1, n+1):
    appended = building[-1] + lastest_add
    building.append(appended)
    longests.append(appended // i)
    lastest_add -= num_counter[i]

for k in range(1, n+1):
    maxindexes = list(i for i, x in enumerate(longests) if x >= k)
    if maxindexes:
        print(maxindexes[-1])
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

line = input()
# N = 3
### line = '2 1 2'
lines = line.split(' ')


dic = {}
for item in lines:
    n = int(item)

    if n in dic.keys():
        dic[n] += 1
    else:
        dic[n] = 1

lis = list(dic.values())
# for item in dic.keys():
#     lis += [dic[item]]

lis.sort(reverse=True)

sublis = []
sublis = lis[:]

def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1

        lis.sort(reverse=True)


for i in range(N):

    lis = sublis[:]
    print(cal(i+1,lis))

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

# リストarrからx個の同じ長さの列を取り出す時の最大の長さ
# 発想: x個取り出す時、ある文字をx個より多く取り出して列に含むことはない
#       一方ある文字をその文字がある数よりも取り出して使うこともできない
#       つまり、min(arr.count(a), x)で、x個の同じ長さの列に使えるaの数がわかる
#       さらに、sum(min(arr.count(a),x))で、x個の同じ長さの列に使える文字の数がわかる
#       よって、sum(min(arr.count(a),x))//xで、x個の同じ長さの列の長さがわかる
#       発展的に、longest(arr,x)までの計算状況からlongest(arr,x+1)が計算できる
def longest(arr, x):    # legacy
    return sum(min(arr.count(a), x) for a in arr) // x


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

counter = collections.Counter(a)
nums = list(counter.values())
num_counter = collections.Counter(nums)
lastest_add = np.count_nonzero(nums)
building = [0]
longests = [0]
for i in range(1, n+1):
    appended = building[-1] + lastest_add
    building.append(appended)
    longests.append(appended // i)
    lastest_add -= num_counter[i]

for k in range(1, n+1):
    maxindexes = list(i for i, x in enumerate(longests) if x >= k)
    if maxindexes:
        print(max(maxindexes))
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

# リストarrからx個の同じ長さの列を取り出す時の最大の長さ
# 発想: x個取り出す時、ある文字をx個より多く取り出して列に含むことはない
#       一方ある文字をその文字がある数よりも取り出して使うこともできない
#       つまり、min(arr.count(a), x)で、x個の同じ長さの列に使えるaの数がわかる
#       さらに、sum(min(arr.count(a),x))で、x個の同じ長さの列に使える文字の数がわかる
#       よって、sum(min(arr.count(a),x))//xで、x個の同じ長さの列の長さがわかる
#       発展的に、longest(arr,x)までの計算状況からlongest(arr,x+1)が計算できる
def longest(arr, x):    # legacy
    return sum(min(arr.count(a), x) for a in arr) // x


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

nums = list(collections.Counter(a).values())
lastest_add = np.count_nonzero(nums)
building = [0]
longests = [0]
for i in range(1, n+1):
    appended = building[-1] + lastest_add
    building.append(appended)
    longests.append(appended // i)
    lastest_add -= nums.count(i)

for k in range(1, n+1):
    maxindexes = list(i for i, x in enumerate(longests) if x >= k)
    if maxindexes:
        print(max(maxindexes))
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter

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

a = Counter(A).values()
B = list(a)
B = np.array(B)
F = [0] * N
for i in range(1,N+1):
    F[i-1] = np.sum(np.minimum(B, i)) / i
num = N
K = 1
while K < N + 1:
    if F[num - 1] >= K:
        print(num)
        K += 1
    else:
        num -= 1
    if num == 0 and K != N + 1:
        for i in range(N-K+1):
            print(0)
        K = N + 1

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

B = [0] * N
for i in A:
    B[i-1] += 1
B = np.array(B)

K = 1
F = [0] * N
for i in range(0,N):
    f = np.sum(np.minimum(B, N-i)) / (N - i)
    while K <= f:
        print(N - i)
        K += 1
    if K == N+1:
        break
    if i == (N - 1) and K != N+1:
        while K != N+1:
            print(0)
            K += 1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

line = input()
# N = 3
### line = '2 1 2'
lines = line.split(' ')


dic = {}
for item in lines:
    n = int(item)

    if n in dic.keys():
        dic[n] += 1
    else:
        dic[n] = 1

lis = []
for item in dic.keys():
    lis += [dic[item]]

lis.sort(reverse=True)

sublis = []
sublis = lis[:]

def cal(k,lis):
    ans = 0
    if (len(lis)<k):
        return 0
    
    while True:
        for k_i in range(k):
            if lis[k_i] == 0:
                return ans
            else:
                lis[k_i] -= 1
        else:
            ans += 1

        lis.sort(reverse=True)


for i in range(N):

    k = i + 1
    lis = sublis[:]
    print(cal(k,lis))

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

def reverse_counting_sort(collection, max):
    bucket = [0]*(max+1)
    for c in collection:
        bucket[c] += 1
    arr = []
    for i in range(max,-1,-1):
        if bucket[i] != 0:
            arr.extend([i]*bucket[i])
    return arr


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

for k in range(1, n+1):
    counts = collections.Counter(a).values()
    counts = reverse_counting_sort(list(counts), n)
    
    eat = 0
    while True:
        if np.count_nonzero(counts) < k:
            break
        else:
            for i in range(k):
                counts[i] -= 1
            eat += 1
            counts = reverse_counting_sort(list(counts), n)
            
    print(eat)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections

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

for k in range(1, n+1):
    counts = collections.Counter(a).values()
    counts = sorted(list(counts), reverse=True)
    
    eat = 0
    while True:
        if np.count_nonzero(counts) < k:
            break
        else:
            for i in range(k):
                counts[i] -= 1
            eat += 1
            counts = sorted(list(counts), reverse=True)
            
    print(eat)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import heapq
import copy

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

num_vec = np.zeros(n + 1)
for ai in a:
    num_vec[ai] += 1

for k in range(1, n+1):
    vec = copy.deepcopy(num_vec)
    
    count = 0
    while True:
        ind_num_maps = list((i, num) for (i, num) in enumerate(vec) if num!=0)

        picks = list(map(lambda map: map[0], heapq.nlargest(k, ind_num_maps, key=lambda map: map[1])))
        for pick in picks:
            vec[pick] -= 1

        if len(picks) == k:
            count += 1
        else:
            break

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect

N = int(input())
A = map(int, input().split())
C = [0]*(N + 1)
for a in A:
    C[a] += 1
sorted_C = sorted(C)

def h(L, i):
    """
    sorted_C[N - i : N]の最小の所に、sorted_C[ : N - i]を順番に積み上げるイメージ
    """
    if i == 1:
        return N
    
    if i > N//2:
        if L[N - i + 1] == 0:
            return 0
        else:
            return 1
    
    for j in range(N - i, 0, - 1):
        if L[j] == 0:
            return L[N - i + 1]
        
        L[N - i + 1] += L[j]
        a = bisect.bisect_right(L[N - i + 2: ], L[N - i + 1])
        L[N - i + 1:] = L[N - i + 2: N - i + 2 + a] + [L[N - i + 1]] + L[N - i + 2 + a :]
        # L[i -1]が大きくなったからソートし直す
        # これはL[0 : i - 2]はソート済みだからbisectでL[0 : i - 2]にL[i - 1]が入るいちを見つければ良い。下の解答参照
    return L[N - i + 1]
        
for i in range(N):
    L = copy.copy(sorted_C)
    print(h(L, i + 1))

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect

N = int(input())
A = map(int, input().split())
C = [0]*(N + 1)
for a in A:
    C[a] += 1
sorted_C = sorted(C)

def h(L, i):
    """
    sorted_C[N - i : N]の最小の所に、sorted_C[ : N - i]を順番に積み上げるイメージ
    """
    if i == 1:
        return N
    
    for j in range(N - i, 0, - 1):
        if L[j] == 0:
            return L[N - i + 1]
        
        L[N - i + 1] += L[j]
        a = bisect.bisect_right(L[N - i + 2: ], L[N - i + 1])
        L[N - i + 1:] = L[N - i + 2: N - i + 2 + a] + [L[N - i + 1]] + L[N - i + 2 + a :]
        # L[i -1]が大きくなったからソートし直す
        # これはL[0 : i - 2]はソート済みだからbisectでL[0 : i - 2]にL[i - 1]が入るいちを見つければ良い。下の解答参照
    return L[N - i + 1]
        
for i in range(N):
    L = copy.copy(sorted_C)
    print(h(L, i + 1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))

B = [0] * N
for i in A:
    B[i-1] += 1

K = 1
F = [0] * N
for i in range(0,N):
    f = 0
    for j in range(N):
        f += min(B[j],N - i)
    f = f / (N - i)
    while K <= f:
        print(N - i)
        K += 1
    if K == N+1:
        break
    if i == (N - 1) and K != N+1:
        while K != N+1:
            print(0)
            K += 1

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
def f(x):
    return int(x) - 1

N = int(input())
A = map(f, input().split())
C = [0]*N
for a in A:
    C[a] += 1
sorted_C = sorted(C)

def h(L, i):
    """
    sorted_C[N - i : N]の最小の所に、sorted_C[ : N - i]を順番に積み上げるイメージ
    """
    if i == 1:
        return N
    
    for j in range(N - i - 1, - 1, - 1):
        if L[j] == 0:
            return L[N - i]
        
        L[N - i] += L[j]
        a = bisect.bisect_right(L[N - i + 1 : ], L[N - i])
        L[N - i:] = L[N - i + 1: N - i + 1 + a] + [L[N - i]] + L[N - i + 1 + a :]
        # L[i -1]が大きくなったからソートし直す
        # これはL[0 : i - 2]はソート済みだからbisectでL[0 : i - 2]にL[i - 1]が入るいちを見つければ良い。下の解答参照
    return L[N - i]
        
for i in range(N):
    L = copy.copy(sorted_C)
    print(h(L, i + 1))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a = sorted([int(x) for x in input().split()])
num = len(set(a))

aa = []
i=0
while(i<n):
    cnt = a.count(a[i])
    aa.append(cnt)
    i += cnt
aa.sort()

# k=1
# ans = n
print(n)

# 2 <= k <= num
# ans = {sum(min(cnt, n//k))} // k
i = len(aa)
for k in range(2, num+1):
    i = bisect.bisect(aa[:i], n//k)
    print(((len(aa)-i)*(n//k)+sum(aa[:i])) // k)

# num < k
# ans = 0
for k in range(num+1, n+1):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
a = sorted([int(x) for x in input().split()])
num = len(set(a))

aa = []
i=0
while(i<n):
    cnt = a.count(a[i])
    aa.append(cnt)
    i += cnt
aa.sort()

# k=1
# ans = n
print(n)

# 2 <= k <= num
# ans = {sum(min(cnt, n//k))} // k
i = 0
for k in range(2, num+1):
    i = bisect.bisect(aa, n//k)
    #while(aa[-i-1] >= n//k):
    #    i += 1
    print(((len(aa)-i)*(n//k)+sum(aa[:i])) // k)
    #aaa = [min(cnt, n//k) for cnt in aa]
    #print(sum(aaa)//k)

# num < k
# ans = 0
for k in range(num+1, n+1):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect

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

B = [0 for _ in range(N)]
for i in A:
    B[i-1] += 1

F = []
for i in range(1,N+1):
    f = 0
    for j in range(N):
        f += min(B[j],i)
    f = f / i
    F.append(f)
F.sort()

for k in range(N):
    x = bisect.bisect_left(F,k+1)
    print(N-x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split()])
num = len(set(a))

aa = []
i=0
while(i<n):
    cnt = a.count(a[i])
    aa.append(cnt)
    i += cnt
aa.sort(reverse=True)

# k=1
print(n)

# 2 <= k <= num
i = 0
for k in range(2, num+1):
    if aa[i] >= n//k:
        i += 1
    print((i*(n//k)+sum(aa[i:])) // k)

# num < k
for k in range(num+1, n+1):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split()])
num = len(set(a))

aa = []
i=0
while(i<n):
    cnt = a.count(a[i])
    #aa.append([a[i], cnt])
    aa.append(cnt)
    i += cnt
aa.sort(reverse=True)

# k=1
print(n)

# 2 <= k <= num
for k in range(2, num+1):
    aaa = [min(cnt, n//k) for cnt in aa]
    print(sum(aaa)//k)

# num < k
for k in range(num+1, n+1):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
from itertools import accumulate
from collections import defaultdict
INF = float("inf")


def solve(N: int, A: "List[int]"):
    c = Counter(A)

    # S = [0]*(N+1)
    # for i in range(1, N+1):
    #     for j in range(N+1):
    #         S[i] += min(c[j], i)
    # print(c)
    # print("目標: ", S)
    d = Counter(c.values())
    d = list(accumulate([d[i] for i in range(N, -1, -1)]))[::-1]
    # print(d)
    S = [0]*(N+1)
    for i in range(1, N+1):
        S[i] = S[i-1] + d[i]

    def isOK(y):
        # print("y: {}, S[{}]: {}, K*y: {}".format(y, y, S[y], K*y))
        return S[y] < K*y

    def binary_search(x):
        ng = -1
        ok = len(x)+1

        while abs(ok - ng) > 1:
            mid = (ok + ng)//2
            if isOK(mid):
                ok = mid
            else:
                ng = mid
        return ng, ok

    for K in range(1, N+1):
        # print("---{}---".format(K))
        ng, ok = binary_search(range(N))
        print(ng)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cards = list(map(int, input().split()))
dic = {}
for card in cards:
    if card in dic.keys():
        dic[card] += 1
    else:
        dic[card] = 1
ary = sorted(dic.values(), reverse=True)
for k in range(1, n+1):
    ans_k = 0
    cnt = 0
    ary_k = ary[:]
    while True:
        for i in range(len(ary_k)):
            if ary_k[i] > 0:
                ary_k[i] -= 1
                cnt += 1
                if cnt == k:
                    cnt = 0
                    ans_k += 1
                    break
            else:
                continue
        else:
            break
    print(ans_k)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from itertools import accumulate

n = int(input())
a = [int(i) for i in readline().split()]

res = [0]*(n+1)
for i in a: res[i] += 1

c = [0]
for i in res:
    if i > 0: c.append(i)
c.sort()#reverse=True)

l = len(c)-1
#print(c)

acc = list(accumulate(c))


memo = {}
def f(m,k):#最初のm個, kずつ
    if m == 0: return 0
    if m < k: return 0
#    if (m,k) in memo:
#        return memo[(m,k)]
    z = 0
    if acc[m]//k >= c[m]:
        return acc[m]//k
    else:
        return f(m-1,k-1)

for i in range(1,n+1):
    print(f(l,i))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from itertools import accumulate

n = int(input())
a = [int(i) for i in readline().split()]

res = [0]*(n+1)
for i in a: res[i] += 1

c = []
for i in res:
    if i > 0: c.append(i)
c.sort()#reverse=True)

l = len(c)
#print(c)

acc = list(accumulate(c))


memo = {}
def f(m,k):#最初のm個, kずつ
    if m == 0: return 0
    if m < k: return 0
    if (m,k) in memo:
        return memo[(m,k)]
    z = 0
    if acc[m-1]//k >= c[m-1]:
        z = acc[m-1]//k
    else:
        z = f(m-1,k-1)
    memo[(m,k)] = z
    return z
    
for i in range(1,n+1):
    print(f(l,i))

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input(""))
A = input("")
A = A.split(" ")
b = set(A)
print(N)
num_value = []
for i in b:
    num_value.append(A.count(i))
num_value.sort(reverse = True)
result = [0 for i in range(N + 1)]
i = 2
memory = copy.deepcopy(num_value)
while i != N + 1 :
    new_num = []
    if len(num_value) >= i :
        for j in range(i):
            num_value[j] -= 1
        while 0 in num_value :
            del num_value[num_value.index(0)]
        result[i] += 1
    else :
        print(result[i])
        i += 1
        num_value = copy.deepcopy(memory)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input(""))
A = input("")
A = A.split(" ")
b = set(A)
print(N)
num_value = []
for i in b:
    num_value.append(A.count(i))
num_value.sort(reverse = True)
result = [0 for i in range(N + 1)]
i = 2
memory = copy.deepcopy(num_value)
while i != N + 1 :
    new_num = []
    if len(num_value) >= i :
        for j in range(i):
            num_value[j] -= 1
        for k in num_value:
            if k > 0:
                new_num.append(k)
        num_value = copy.deepcopy(new_num)
        result[i] += 1
    else :
        print(result[i])
        i += 1
        num_value = copy.deepcopy(memory)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input(""))
A = input("")
#N = 5
#A = "1 2 3 4 5"
A = A.split(" ")
num = {}
print(N)
for i in A:
    if not i in num.keys():
        num[i] = A.count(i)
num_value = list(num.values())
num_value.sort(reverse = True)
result = [0 for i in range(N + 1)]
i = 2
memory = copy.deepcopy(num_value)
while i != N + 1 :
    new_num = []
    if len(num_value) >= i :
        for j in range(i):
            num_value[j] -= 1
        for k in num_value:
            if k != 0:
                new_num.append(k)
        num_value = copy.deepcopy(new_num)
        result[i] += 1
    else :
        print(result[i])
        i += 1
        num_value = copy.deepcopy(memory)

Submission status: Time Limit Exceeded

Solution code:
import copy

def insort(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x[0] < a[mid][0]: hi = mid
        else: lo = mid+1
    a.insert(lo, x)
"""
a =[[1, 1], [1, 3], [1, 4]]
insort(a, [0, 2])
print(a)"""

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

aa = []

i=0
while(True):
    if i>=n:
        break
    cnt = a.count(a[i])
    aa.append([cnt, a[i]])
    i += cnt

aa.sort()

# k=1
print(n)

# k>=2
for k in range(2, len(aa)+1):
    ans = 0
    kaa = copy.deepcopy(aa)
    while(True):
        #print(kaa)
        if kaa[len(kaa)-k][0] <= 0:
            print(ans)
            break
        else:
            for j in range(k):
                kaa[len(kaa)-j-1][0] -= 1
            ans += 1
            kaa, tmp = kaa[:len(kaa)-k], kaa[len(kaa)-k:]
            #print(kaa)
            for l in tmp:
                #print(l)
                insort(kaa, l)
#            kaa.sort(key=lambda x: x[0], reverse=True)

for i in range(n - len(aa)):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

aa = []

i=0
while(True):
    if i>=n:
        break
    cnt = a.count(a[i])
    aa.append([a[i], cnt])
    i += cnt

aa.sort(key=lambda x: x[1], reverse=True)
#print(aa)
    
# k=1
print(n)

# k>=2
for k in range(2, len(aa)+1):
    ans = 0
    kaa = copy.deepcopy(aa)
    while(True):
        #print(kaa)
        if kaa[k-1][1] <= 0:
            print(ans)
            break
        else:
            for j in range(k):
                kaa[j][1] -= 1
            ans += 1
            kaa.sort(key=lambda x: x[1], reverse=True)

for i in range(n - len(aa)):
    print(0)

Submission status: Time Limit Exceeded

Solution code:
#そうか、値のみに注目すればいいね。
import collections

n = int(input())
a = [int(i) for i in input().split()]
d = collections.Counter(a)
d = list(d.values())
d.sort()

for k in range(1,n+1):
    c = d.copy()
    ans = -1
    state = 0
    while(state==0):
        ans += 1
        c.sort()
        l = len(c)
        if l<k:
            state = 1
        else:
            if c[l-k]<=0:
                state=1
                break
            else:
                for i in range(l-k,l):
                    c[i] -= 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = [int(i) for i in input().split()]
d = collections.Counter(a)

for k in range(1,n+1):
#k = 2
    c = d.copy()
    ans = -1
    state = 0
    while(state==0):
        ans += 1
        values, counts = zip(*c.most_common(k))
        if len(values)<k:
            state=1
        else:
            for i,v in enumerate(values):
                if counts[i] ==0:
                    state = 1
                    break
                c[v] -= 1

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# F - Distinct Numbers
def Distinct(N, A):
    ans = [0] * N
    ans[0] = N

    uniq_num = len(set(A))

    freq = [0] * N
    for x in A: freq[x-1] += 1

    for i in range(1, uniq_num):
        cnt = 0
        arr = freq[:]
        for _ in A:
            arr.sort(reverse=True)
            tmp = arr[i]
            if tmp > 0:
                cnt += tmp
                arr = [arr[j] - tmp if j < i+1 else arr[j] for j in range(N)]
            else:
                break
        ans[i] = cnt

    print('\n'.join(map(str, ans)))

N = int(input())
A = list(map(int, input().split()))
Distinct(N, A)

Submission status: Time Limit Exceeded

Solution code:
# F - Distinct Numbers
def Distinct(N, A):
    ans = [0] * N
    ans[0] = N

    uniq_num = len(set(A))

    freq = [0] * N
    for x in A: freq[x-1] += 1

    for i in range(1, uniq_num):
        cnt = 0
        arr = freq
        while True:
            arr = sorted(arr, reverse=True)
            tmp = arr[i]
            if tmp > 0:
                cnt += tmp
                arr = [arr[j] - tmp if j < i+1 else arr[j] for j in range(N)]
            else:
                break
        ans[i] = cnt

    print('\n'.join(map(str, ans)))

N = int(input())
A = list(map(int, input().split()))
Distinct(N, A)

Submission status: Time Limit Exceeded

Solution code:
import sys 
import collections as cl

N=int(input())
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[sum([min(NumberList[i],x) for i in range(LengthOfNumberList)])/x for x in range(1,N+1)]

pin=N-1
for K in range(1,N+1):
    while pin>=0 and K>FormulaList[pin]:
        pin-=1
    print(pin+1)

Submission status: Time Limit Exceeded

Solution code:
import sys 
import collections as cl

N=int(input())
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberList=[x for x in c.values()]
LengthOfNumberList=len(NumberList)
FormulaList=[sum([min(NumberList[i],x) for i in range(LengthOfNumberList)])/x for x in range(1,N+1)]
FormulaList.sort(reverse=True)

pin=N-1
for K in range(1,N+1):
    while pin>=0 and K>FormulaList[pin]:
        pin-=1
    print(pin+1)

Submission status: Time Limit Exceeded

Solution code:
# F - Distinct Numbers
def Distinct(N, A):
    ans = [0] * N
    ans[0] = N

    uniq_num = len(set(A))

    freq = [0] * N
    for x in A: freq[x-1] += 1

    for i in range(1, uniq_num):
        cnt = 0
        arr = freq
        while True:
            arr = sorted(arr, reverse=True)
            tmp = arr[i]
            if tmp > 0:
                cnt += tmp
                for j in range(i+1): arr[j] -= tmp
            else:
                break
        ans[i] = cnt

    print('\n'.join(map(str, ans)))

N = int(input())
A = list(map(int, input().split()))
Distinct(N, A)