QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#392253#6750. CalculateHCCHWA 16ms10904kbPython31.9kb2024-04-17 13:12:262024-04-17 13:12:27

Judging History

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

  • [2024-04-17 13:12:27]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:10904kb
  • [2024-04-17 13:12:26]
  • 提交

answer

from queue import LifoQueue
import sys
sys.setrecursionlimit(1000000)
ss:str = input()
st = LifoQueue()
ma = {}
s = ""
pos = []

for i in range(len(ss)):
    if ss[i]=='(':
        st.put(i)

    elif ss[i]==')':
        la = st.get()
        ma[la] = i
        ma[i] = la

    else:
        ma[i] = -1

    if ss[i] == '?':
        pos.append(i)


# def calc(l, r):
#     pt = l
#     while pt < r and s[pt].isdigit():
#         pt += 1
    
#     if pt == r:
#         return int(s[l:r])
    
#     if s[l] == '(':
#         pt = ma[l]+1
#         res = calc(l+1, ma[l])
#     else:
#         res = calc(l, pt)
    
#     if pt == r:
#         return res
#     if s[pt] == '+':
#         res += calc(pt+1, r)
#     else:
#         res -= calc(pt+1, r)

#     return res

# [l,r)
def calc(l, r):
    print(s+": "+str(l)+" "+str(r))
    if s[l:r].isdigit():
        return int(s[l:r])
    
    pt = l
    res = 0
    if s[l] == '(':
        pt = ma[l]+1
        res = calc(l+1, ma[l])
        if pt == r:
            return res
        
    else:
        while pt < r and s[pt].isdigit():
            pt += 1
        res = int(s[l:pt])

    sign = 1
    if s[pt] == '-':
        sign = -1
    return res + sign * calc(pt+1, r)
    


    
mx = 0
if len(pos) == 0:
    s = ss
    mx = eval(s)

elif len(pos) ==1:
    s = ss[:pos[0]] + '0' + ss[pos[0]+1:]
    mx = calc(0, len(s))
    for i in range(10): 
        s = ss[:pos[0]] + str(i) + ss[pos[0]+1:]
        mx = max(mx, eval(s))
        
elif len(pos) == 2:
    s = ss[:pos[0]] + '0' + ss[pos[0]+1:pos[1]] + '0' + ss[pos[1]+1 : ]
    mx = calc(0, len(s))

    for i in range(10):
        s = ss[:pos[0]] + str(i) + ss[pos[0]+1:]

        for j in range(10):
            s = s[:pos[1]] + str(j) + s[pos[1]+1:]
            mx = max(mx, eval(s))

print(mx)


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 10904kb

input:

?+?

output:

0+0: 0 3
0+0: 2 3
18

result:

wrong output format Expected integer, but "0+0:" found