[Offer收割]编程练习赛4 register

Ended

Participants:899

Verdict:Time Limit Exceeded
Score:80 / 100
Submitted:2016-08-07 13:41:29

Lang:Python2

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import collections
n = input()
s = map(intraw_input().split())
d = collections.Counter(s)
m = max(d[i] for i in d)
if m >= (n + 1) / 2 + 1:
    print -1
    exit()
ret = []
for i in range(n):
    cm = d.most_common(1)[0]
    if n & 1 and m == n / 2 + 1:
        m -= 1
    else:
        for i in sorted(d.keys()):
            if len(ret) == 0 or i != ret[-1]:
                c = i
                break
    ret.append(c)
    d[c] -= 1
    if d[c] == 0del d[c]
    n -= 1
    
print ' '.join(map(strret))
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX