Universal Cup Judging System

Universal Cup

時間限制: 3.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

非負整数の組 $W, S$ が与えられます。

パフィンの Pataro は1人でカードゲームをしています。カードにはカード w とカード s の2種類があります。

最初、Pataro はタイプ w のカードを $W$ 枚、タイプ s のカードを $S$ 枚持っており、得点は $0$ です。彼は持っているカードがすべてなくなるまで、手持ちのカードを1枚ずつ消費することを繰り返します。$i$ 番目に消費したカードがカード s であるとき、次の効果が発生します:

  • $(i - 1)$ 番目、$(i - 2)$ 番目、$(i - 3)$ 番目に消費したカードのうち、カード w であるものの枚数を $x$ とする。彼は $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

注記

1つ目の例では、Pataro が w, w, s, s, w, w, w, s の順にカードを消費するのが最適です。

  • $3$ 番目に消費されたカードはカード s です。$2$ 番目、$1$ 番目、$0$ 番目に消費されたカードのうち、タイプ w のカードは $2$ 枚あるため、彼は $27 \times \left(\frac{4}{3}\right)^2 = 48$ の得点を得ます。
  • $4$ 番目に消費されたカードはカード s です。$3$ 番目、$2$ 番目、$1$ 番目に消費されたカードのうち、タイプ w のカードは $2$ 枚あるため、彼は $27 \times \left(\frac{4}{3}\right)^2 = 48$ の得点を得ます。
  • $8$ 番目に消費されたカードはカード s です。$7$ 番目、$6$ 番目、$5$ 番目に消費されたカードのうち、タイプ w のカードは $3$ 枚あるため、彼は $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.