結果
問題 | No.2927 Reverse Polish Equation |
ユーザー |
👑 |
提出日時 | 2024-07-17 00:22:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 644 ms / 2,000 ms |
コード長 | 799 bytes |
コンパイル時間 | 298 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 128,848 KB |
最終ジャッジ日時 | 2024-10-16 00:20:21 |
合計ジャッジ時間 | 14,364 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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: 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)