QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742393#3136. The Spectrumvwxyz#TL 15ms10696kbPython3880b2024-11-13 16:31:172024-11-13 16:31:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 16:31:24]
  • 评测
  • 测评结果:TL
  • 用时:15ms
  • 内存:10696kb
  • [2024-11-13 16:31:17]
  • 提交

answer

N=int(input())
A=list(map(int,input().split()))
M=1000
cnt=[0]*M
for a in A:
    cnt[a]+=1
l,r=0,max(A)
def solve(X,cnt):
    if max(cnt)==0:
        retu=[X]
    else:
        retu=[]
        for d in range(M-1,-1,-1):
            if cnt[d]:
                for y in (d,r-d):
                    cnt_=cnt[:]
                    ok=True
                    for x in X:
                        cnt_[abs(x-y)]-=1
                        if cnt_[abs(x-y)]<0:
                            ok=False
                    if ok:
                        retu+=solve(X+[y],cnt_)
                break
    return retu
cnt[r-l]-=1
ans_lst=solve([l,r],cnt)
le=len(ans_lst)
for i in range(le):
    ans_lst[i].sort()
    ans_lst[i]=tuple(ans_lst[i])
ans_lst=list(set(ans_lst))
le=len(ans_lst)
ans_lst.sort()
print(le)
for i in range(le):
    print(*ans_lst[i])

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 10580kb

input:

4
2 2 2 4 4 6

output:

1
0 2 4 6

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 9ms
memory: 10624kb

input:

5
3 3 6 9 9 12 12 15 18 21

output:

2
0 3 12 15 21
0 6 9 18 21

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 11ms
memory: 10696kb

input:

4
5 6 7 8 9 10

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 15ms
memory: 10628kb

input:

9
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 6 6 7 7 8 8 8 9 9 10 10 11 11 12 12 12 13 14 15

output:

4
0 1 3 4 5 7 12 13 15
0 1 3 8 9 11 12 13 15
0 2 3 4 6 7 12 14 15
0 2 3 8 10 11 12 14 15

result:

ok 5 lines

Test #5:

score: -100
Time Limit Exceeded

input:

62
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...

output:


result: