QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153136#5607. Cribbage On SteroidsLamberlainMuliWA 17ms8296kbPython32.7kb2023-08-29 14:36:192023-08-29 14:36:20

Judging History

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

  • [2023-08-29 14:36:20]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:8296kb
  • [2023-08-29 14:36:19]
  • 提交

answer

n=int(input())
count=0
sets=[]
cards=[]
ranks=['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
value={}
for rank in ranks:
    if rank == 'A':
        value[rank]=1
    elif rank in ['T','J','Q','K']:
        value[rank]=10
    else:
        value[rank]=int(rank)
        
while len(cards)!=n:
    new=[x for x in input().split()]
    cards=cards+new
    sets.append(new)
freq={}
freq_values={}
for card in cards:
    if card not in freq:
        freq[card]=1
    else:
        freq[card]+=1

for card in cards:
    if value[card] not in freq_values:
        if card == 'A':
            freq_values[1]=1
        elif card in ['T','J','Q','K']:
            freq_values[10]=1
        else:
            freq_values[int(card)]=1
    else:
        if card == 'A':
            freq_values[1]+=1
        elif card in ['T','J','Q','K']:
            freq_values[10]+=1
        else:
            freq_values[int(card)]+=1
            
for rank in ranks:
    if rank not in cards:
        freq[rank]=0
    if value[rank] not in freq_values:
        if rank=='A':
            freq_values[1]=0
        elif rank in ['T','J','Q','K']:
            freq_values[10]=0
        else:
            freq_values[int(rank)]=0
            
fifteens=[]
for i in range(2,16):
    def solve(j,i,sol,sm):
        global sols
        if j==i:
            if sm==15:
                fifteens.append(sol)
        elif sm>15:
            return
        else:
            mn=1 if len(sol)==0 else sol[-1]
            for k in range(mn,min(11,15-sm+1)):
                solve(j+1,i,sol+[k],sm+k)
    solve(0,i,[],0)
from math import *
points=0
for fifteen in fifteens:
    comb_freq={}
    for num in fifteen:
        if num not in comb_freq:
            comb_freq[num]=1
        else:
            comb_freq[num]+=1
    if all([freq_values[x]>=comb_freq[x] for x in comb_freq.keys()]):
        p=1
        for y in comb_freq.keys():
            p*=comb(freq_values[y],comb_freq[y])
        points+=2*p

for card,f in freq.items():
    if f>=2:
        points+=f*(f-1)
for set in sets:
    f={}
    for card in set:
        if card not in f:
            f[card]=1
        else:
            f[card]+=1
    for rank in ranks:
        if rank not in set:
            f[rank]=0
    start=0
    while start<=10:
        mx=1
        for run in range(3,13-start+1):
            if all([(f[ranks[start+i]]>0) for i in range(run)]):
                mx=run
        if mx>=3:
            prod=1
            for i in range(mx):
                prod*=f[ranks[start+i]]
            points+=prod*mx
        start = start+mx        
print(points)

详细

Test #1:

score: 100
Accepted
time: 9ms
memory: 8292kb

input:

5
4 5 6 5 5

output:

23

result:

ok single line: '23'

Test #2:

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

input:

13
A 2 3 4 5
6 7 8 9 T
J Q K

output:

71

result:

ok single line: '71'

Test #3:

score: 0
Accepted
time: 17ms
memory: 8132kb

input:

10
2 2 3 4 5 8 9 T J Q

output:

45

result:

ok single line: '45'

Test #4:

score: 0
Accepted
time: 8ms
memory: 8296kb

input:

5
5 5 5 5 J

output:

28

result:

ok single line: '28'

Test #5:

score: 0
Accepted
time: 12ms
memory: 8176kb

input:

5
5 5 5 5 5

output:

40

result:

ok single line: '40'

Test #6:

score: 0
Accepted
time: 17ms
memory: 8104kb

input:

11
A 2 3 5 6 7 8 T J Q K

output:

41

result:

ok single line: '41'

Test #7:

score: -100
Wrong Answer
time: 12ms
memory: 8288kb

input:

20
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5

output:

15208

result:

wrong answer 1st lines differ - expected: '20308', found: '15208'