結果

問題 No.2927 Reverse Polish Equation
ユーザー VvyLwVvyLw
提出日時 2024-10-14 17:19:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,245 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,920 KB
最終ジャッジ日時 2024-10-16 00:33:34
合計ジャッジ時間 13,692 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,624 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 150 ms
11,776 KB
testcase_08 AC 258 ms
12,752 KB
testcase_09 WA -
testcase_10 AC 51 ms
10,880 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 31 ms
10,752 KB
testcase_24 AC 30 ms
10,752 KB
testcase_25 AC 30 ms
10,752 KB
testcase_26 AC 31 ms
10,496 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 TLE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 WA -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 RE -
権限があれば一括ダウンロードができます

ソースコード

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})
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(x)==y else -1)
0