QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#392253 | #6750. Calculate | HCCH | WA | 16ms | 10904kb | Python3 | 1.9kb | 2024-04-17 13:12:26 | 2024-04-17 13:12:27 |
Judging History
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)
詳細信息
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