Universal Cup Judging System

Universal Cup

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

俾你一對非負整數 $W, S$。

海鸚 Pataro 自己一個玩緊紙牌遊戲。紙牌有兩種類型:牌 w 同牌 s。

一開始,Pataro 有 $W$ 張 w 類牌同 $S$ 張 s 類牌,而佢嘅分數係 $0$。佢不斷從手中嘅牌消耗一張,直到所有牌都消耗晒為止。當第 $i$ 張被消耗嘅牌係 s 類牌嗰陣,會觸發以下效果:

  • 喺第 $(i - 1)$ 張、第 $(i - 2)$ 張同第 $(i - 3)$ 張被消耗嘅牌入面,設 $x$ 為當中屬於 w 類牌嘅張數。佢會獲得 $27 \times \left(\frac{4}{3}\right)^x$ 分。

為方便起見,假設喺位置 $0$ 或更早位置消耗嘅牌唔係 w 類牌。

請搵出 Pataro 透過按適當順序消耗紙牌所能獲得嘅最大總分。可以證明,所求答案永遠係一個整數。

請對 $T$ 組測試數據解決上述問題。

輸入格式

輸入按以下格式給出:

T
case1
case2
:
caseT

每組測試數據按以下格式給出:

W S
  • $1 \le T \le 10^4$
  • $0 \le W, S \le 10^{16}$
  • 所有輸入值都係整數。

輸出格式

輸出 $T$ 行。 第 $i$ 行應該包含第 $i$ 組測試數據嘅答案。

範例

範例輸入 1

3
5 3
12 9
2026 328

範例輸出 1

160
484
20992

備註

喺第一個範例入面,Pataro 按 w, w, s, s, w, w, w, s 嘅順序消耗紙牌係最優嘅。

  • 第 $3$ 張被消耗嘅牌係 s 類牌。喺第 $2$ 張、第 $1$ 張同第 $0$ 張被消耗嘅牌入面,有 $2$ 張 w 類牌,所以佢獲得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 $4$ 張被消耗嘅牌係 s 類牌。喺第 $3$ 張、第 $2$ 張同第 $1$ 張被消耗嘅牌入面,有 $2$ 張 w 類牌,所以佢獲得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 $8$ 張被消耗嘅牌係 s 類牌。喺第 $7$ 張、第 $6$ 張同第 $5$ 張被消耗嘅牌入面,有 $3$ 張 w 類牌,所以佢獲得 $27 \times \left(\frac{4}{3}\right)^3 = 64$ 分。

因此,Pataro 可以獲得嘅總分係 $160$。無論點樣消耗紙牌,都唔可能獲得大過 $160$ 嘅分數,所以答案係 $160$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1484EditorialOpen题解jianglyView
#1342EditorialOpen题解MilmonView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.