結果
問題 |
No.2927 Reverse Polish Equation
|
ユーザー |
👑 |
提出日時 | 2024-07-22 14:00:36 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 747 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,624 KB |
実行使用メモリ | 98,304 KB |
最終ジャッジ日時 | 2024-10-16 00:20:37 |
合計ジャッジ時間 | 6,312 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 RE * 26 |
ソースコード
Q, Y = map(int, input().split()) S = input().split() assert 0 <= Y <= 10**9 def rev_polish(x): A = [] for s in S: if s in ('+', 'min', 'max'): a = A.pop() b = A.pop() if s == '+': A.append(a + b) if s == 'min': A.append(min(a, b)) if s == 'max': A.append(max(a, b)) else: if s == 'X': A.append(x) else: A.append(int(s)) return A[0] ok, ng = Y, -1 while ok - ng > 1: mid = (ok + ng) // 2 if rev_polish(mid) >= Y: ok = mid else: ng = mid if rev_polish(ok) == Y: print(ok) else: print(-1)