This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
from collections import Counter
import sys as sus
input = sus.stdin.readline
n, m = map(int, input().split())
c = list(map(int, input().split()))
ct = Counter(c)
o = ct.most_common()
odd = Counter()
eve = Counter()
for i in range(n - 1):
if i % 2:
odd[(c[i], c[i + 1])] += 1
else:
eve[(c[i], c[i + 1])] += 1
out = []
for i in range(1, m + 1):
res = 0
for v, vc in o:
if v == i:
continue
bl = odd[(i, v)] + odd[(v, i)]
br = eve[(i, v)] + eve[(v, i)]
bad = min(bl, br)
res = max(res, vc - bad)
if bad == 0:
break
out.append(n - res - ct[i])
print('\n'.join(map(str, out)))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |