QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#392255#6750. CalculateHCCHWA 146ms12576kbPython31.8kb2024-04-17 13:12:512024-04-17 13:12:52

Judging History

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

  • [2024-04-17 13:12:52]
  • 评测
  • 测评结果:WA
  • 用时:146ms
  • 内存:12576kb
  • [2024-04-17 13:12:51]
  • 提交

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):
    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: 100
Accepted
time: 16ms
memory: 10800kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: 0
Accepted
time: 144ms
memory: 12524kb

input:

((9)-(((8)-(2))+(((1+(1))-(1+((2)+2+2)))+(5)+4))+(((7)-((9)+3))-((8)-(0-(2))+0))+((6)-(6+(((4)-(9))-(8-((9)+(1))+(0)))+(2-((9)+7))-(1)))-((((7)+(1))-((3)+(3)))-((2)-((6)-((3)-(8)))))+(2+0-((6)-(1))))-((((3)-(((0)+((4)-(9))+((6+8)+4)+(5)-(4-(3)-(8)))-((8)-(2))))+(((2)-(4))+(6)-(2))+(6-(1))-((2+9)-(3+...

output:

-63

result:

ok 1 number(s): "-63"

Test #4:

score: 0
Accepted
time: 146ms
memory: 12324kb

input:

(((((4)-((5)+(1))-(6-(8-(1))+((0)+(9))))+((2-(2))+(3+3-(((7)-(6))-(3))+(((3)+((5)-((0)-(6-(0)))))+((0)+((0)-(7)))+1-((3)-((8)-(8)))))))-(((((5-(3)-((((8)+0)+(9)-((7)-(9)))-(7)))+(2))+8+((4)-(6)+((5)-((7)+(2))))-(8-((7)+(3)+(9))))-(((9-(9-(8)))+1-((((4)+(9))+(8))+(2+(7)+3)))+((((6)+(2))-(1)-((((6+7-(...

output:

356

result:

ok 1 number(s): "356"

Test #5:

score: -100
Wrong Answer
time: 139ms
memory: 12576kb

input:

((((((0+(5))+6)-((4)+(((7)+2)+6)-((((7)-(9))-(1))-((8-(2))+(5))-(2-((5)-(8))))-(3)))+((8)-(6)+3))+(7-(((4)+(6))+(((6)-(4))-(5))-(5-(4))-(5)+(2-(2)))+(6+(3+(2)+(7)+3)))+(((3)+(4)+(7)-(6-(5)))-((9+(8))+((1)-(0)))+((((8)+1)-(4))+(4))+(((4)-(4))+9+(((8)+3)-(6)+5)))-(((((5)+(9))-((3)-(0)))+((((0)+3)-(2))...

output:

-100

result:

wrong answer 1st numbers differ - expected: '-185', found: '-100'