結果

問題 No.2927 Reverse Polish Equation
ユーザー VvyLwVvyLw
提出日時 2024-10-14 17:10:57
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,358 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 308,604 KB
最終ジャッジ日時 2024-10-16 00:33:14
合計ジャッジ時間 6,686 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
57,600 KB
testcase_01 AC 43 ms
52,736 KB
testcase_02 AC 44 ms
52,992 KB
testcase_03 AC 43 ms
52,608 KB
testcase_04 AC 44 ms
53,504 KB
testcase_05 AC 43 ms
53,248 KB
testcase_06 AC 44 ms
53,376 KB
testcase_07 AC 176 ms
76,672 KB
testcase_08 AC 296 ms
84,096 KB
testcase_09 AC 199 ms
76,288 KB
testcase_10 AC 71 ms
67,200 KB
testcase_11 AC 305 ms
84,224 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# LPSolverで挑戦するも失敗
# from pulp import LpProblem, LpVariable, LpMinimize, value, PULP_CBC_CMD, LpInteger
# _,y=map(int,input().split())
# s=list(input().split())
# sk=[]
# op = {'+': lambda x,y: f"({x}+{y})",
#       'max': lambda x,y: f"max({x},{y})",
#       'min': lambda x,y: f"min({x},{y})"}
# prob=LpProblem(sense=LpMinimize)
# for t in s:
#     if t in op:
#         b,a=sk.pop(),sk.pop()
#         sk.append(op[t](a,b))
#     else: sk.append(t)
# print(sk[0])
# x=LpVariable("x",lowBound=0,cat=LpInteger)
# prob+=eval(sk[0],{"X":x,
#                   "max": lambda a,b: a if a>=b else b,
#                   "min": lambda a,b: a if a<=b else b})==y
# prob+=x
# prob.solve(PULP_CBC_CMD(msg=False))
# if prob.status!=1: print(-1)
# else: print(int(value(x)))

_,y=map(int,input().split())
s=list(input().split())
sk=[]
op = {'+': lambda x,y: f"({x}+{y})",
      'max': lambda x,y: f"max({x},{y})",
      'min': lambda x,y: f"min({x},{y})"}
for t in s:
    if t in op:
        b,a=sk.pop(),sk.pop()
        sk.append(op[t](a,b))
    else: sk.append(t)
# print(sk[0])
def f(x): return eval(sk[0],{"X":x,
                   "max": lambda a,b: a if a>=b else b,
                   "min": lambda a,b: a if a<=b else b})
ok,ng=(1<<61)-1,-1
while abs(ok-ng)>1:
    x=(ok+ng)//2
    if f(x)>=y: ok=x
    else: ng=x
print(ok if f(ok)==y else -1)
0