結果
問題 | No.2927 Reverse Polish Equation |
ユーザー |
![]() |
提出日時 | 2024-10-13 19:23:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 623 ms / 2,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 114,968 KB |
最終ジャッジ日時 | 2024-10-16 00:31:43 |
合計ジャッジ時間 | 13,274 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
Q, Y = map(int,input().split()) S = input().split() code = {"+":0,"min":1,"max":2} def f(x): stack = [] for s in S: if s.isdigit(): stack.append(int(s)) elif s == "X": stack.append(x) else: a = stack.pop() b = stack.pop() match code[s]: case 0: stack.append(a + b) case 1: stack.append(min(a,b)) case 2: stack.append(max(a,b)) dum = 0 return stack[0] lb = -1 ub = Y while ub - lb > 1: mid = (ub + lb) // 2 if f(mid) >= Y: ub = mid else: lb = mid if f(ub) == Y: print(ub) else: print(-1)