Submission #3302957

Source Code Expand

Copy
from collections import defaultdict
import sys
n = int(input())
v = list(map(int, input().split()))

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)

# 偶数番目のヒストグラムを作る
for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]
#print(l_even)

# 奇数番目のヒストグラムを作る
for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])
#print(l_odd)
top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: # つまり全部同じ数字のとき
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        # 2パターン試す
        l_odd_1 = [l for l in l_odd if l[0] != l_odd[-2][0]]
        sum_odd_1 = sum(l[1] for l in l_odd_1)
        l_even_1 = [l for l in l_even if l[0] != top_even]
        sum_even_1 = sum(l[1] for l in l_even_1)
        sum_1 = sum_odd_1 + sum_even_1

        l_odd_2 = [l for l in l_odd if l[0] != top_odd]
        sum_odd_2 = sum(l[1] for l in l_odd_2)
        l_even_2 = [l for l in l_even if l[0] != l_even[-2][0]]
        sum_even_2 = sum(l[1] for l in l_even_2)
        sum_2 = sum_odd_2 + sum_even_2

        if sum_1 < sum_2:
            print(sum_1)
        else:
            print(sum_2)
        sys.exit()
else:
    l_odd = [l for l in l_odd if l[0] != top_odd]

sum_odd = sum(l[1] for l in l_odd)
#print(l_odd, sum_odd)

l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)
#print(l_even, sum_even)

res = sum_odd + sum_even
print(res)

Submission Info

Submission Time
Task C - /\/\/\/
User showyou41
Language Python3 (3.4.3)
Score 300
Code Size 1680 Byte
Status
Exec Time 161 ms
Memory 22024 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1_3132.txt, sample2_iw.txt, sample3_1111.txt
All 300 / 300 ababa_0.txt, ababa_1.txt, eq_0.txt, eq_1.txt, rnd_17.txt, sample1_3132.txt, sample2_iw.txt, sample3_1111.txt, top2_0.txt, top2_1.txt, top2_2.txt, top2_3.txt, top2modoki_0.txt, top2modoki_1.txt, top2modoki_2.txt, top2modoki_3.txt, vary_1.txt, vary_2.txt, vary_3.txt, zoro_0.txt
Case Name Status Exec Time Memory
ababa_0.txt 92 ms 15208 KB
ababa_1.txt 95 ms 15244 KB
eq_0.txt 65 ms 14232 KB
eq_1.txt 63 ms 14232 KB
rnd_17.txt 62 ms 14264 KB
sample1_3132.txt 21 ms 3316 KB
sample2_iw.txt 21 ms 3316 KB
sample3_1111.txt 21 ms 3316 KB
top2_0.txt 68 ms 14360 KB
top2_1.txt 70 ms 14908 KB
top2_2.txt 69 ms 14140 KB
top2_3.txt 72 ms 14240 KB
top2modoki_0.txt 69 ms 14252 KB
top2modoki_1.txt 70 ms 14148 KB
top2modoki_2.txt 67 ms 14240 KB
top2modoki_3.txt 68 ms 14360 KB
vary_1.txt 132 ms 21184 KB
vary_2.txt 161 ms 22024 KB
vary_3.txt 107 ms 16304 KB
zoro_0.txt 21 ms 3316 KB