結果
問題 |
No.2927 Reverse Polish Equation
|
ユーザー |
👑 |
提出日時 | 2024-07-27 11:47:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 638 ms / 2,000 ms |
コード長 | 843 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 129,104 KB |
最終ジャッジ日時 | 2024-10-16 00:20:45 |
合計ジャッジ時間 | 13,711 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
Q, Y = map(int, input().split()) S = input().split() assert 1 <= Q <= 2 * 10**5 assert 0 <= Y <= 10**14 assert len(S) == Q def rev_poland(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: assert 0 <= int(s) <= 10**9 A.append(int(s)) return A[0] ok, ng = 10**14, -1 while ok - ng > 1: mid = (ok + ng) // 2 if rev_poland(mid) >= Y: ok = mid else: ng = mid if rev_poland(ok) == Y: print(ok) else: print(-1)