Codeforces Round 1116 (Div. 1)
A
仙女仓库里的烫土豆游戏
Hot Potatoes at the Fairy Warehouse
Codeforces
1200
原题
←B →

仙女仓库里的烫土豆游戏AI (CI翻译)

On a quiet afternoon at the Fairy Warehouse, Ithea gathers Chtholly, Nephren, and the other leprechauns for one last game before dinner: Hot Potatoes.

在仙女仓库一个宁静的午后,Ithea 召集 Chtholly、Nephren 和其他妖精,在晚餐前玩最后一场游戏:烫土豆。AI (CI翻译)

There are $2n$ leprechauns sitting in a circle, numbered from $1$ to $2n$ clockwise. They are divided into two teams: leprechauns with odd numbers belong to the Red Team, while those with even numbers belong to the Blue Team.

有 $2n$ 个妖精围成一圈,按顺时针方向编号为 $1$ 到 $2n$。他们分为两队:编号为奇数的妖精属于红队,编号为偶数的妖精属于蓝队。AI (CI翻译)

Initially, some leprechauns hold a potato. The game then lasts for $k$ rounds.

起初,部分妖精手里拿着土豆。随后,游戏进行 $k$ 轮。AI (CI翻译)

At the beginning of each round, both teams know the current positions of all potatoes. Then, simultaneously, every leprechaun holding a potato does exactly one of the following:

每一轮开始时,两队都知道当前所有土豆的位置。接着,所有手里拿着土豆的妖精同时执行以下操作之一:AI (CI翻译)

  • Keep the potato, or
  • Pass the potato to the next leprechaun clockwise, provided that the next leprechaun does not hold a potato at the beginning of the round.
  • 保留土豆;或
  • 将土豆传给顺时针方向的下一个妖精,前提是该妖精在本轮开始时没有拿着土豆。
AI (CI翻译)

If the next leprechaun holds a potato at the beginning of the round, the current holder must keep their potato. Whether a potato can be passed depends only on the positions of the potatoes at the beginning of the round.

如果下一个妖精在本轮开始时拿着土豆,当前持有者就必须保留自己的土豆。能否传递土豆只取决于本轮开始时土豆的位置。AI (CI翻译)

Under these rules, every leprechaun holds at most one potato at any time.

按照这些规则,任何时刻每个妖精最多拿着一个土豆。AI (CI翻译)

When all $k$ rounds are over, the final bell rings. Every leprechaun still holding a potato is eliminated from the game. The score of each team is defined as the number of eliminated leprechauns on the other team. All members of each team cooperate and share all available information to maximize their team's score.

$k$ 轮全部结束后,终场铃声响起。此时仍拿着土豆的妖精将被淘汰。每队的得分定义为对方队伍中被淘汰的妖精数量。每队的所有成员相互合作,并共享所有可用信息,以最大化本队得分。AI (CI翻译)

Find the scores of the Red Team and the Blue Team if both teams play optimally. It can be shown that the scores under optimal play are uniquely determined.

求两队都采用最优策略时,红队和蓝队的得分。可以证明,双方最优策略下的得分是唯一确定的。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains two integers $n$ and $k$ ($1\le n\le 10^5$, $1\le k\le 10^9$) — half the number of leprechauns and the number of rounds.

每个测试用例的第一行包含两个整数 $n$ 和 $k$($1\le n\le 10^5$,$1\le k\le 10^9$),分别表示妖精数量的一半和游戏轮数。AI (CI翻译)

The second line contains a binary string $s$ of length $2n$ ($s_i=\texttt{0}$ or $\texttt{1}$) describing the initial state of the game. If $s_i=\texttt{1}$, leprechaun $i$ initially holds a potato; otherwise, they do not.

第二行包含一个长度为 $2n$ 的二进制字符串 $s$($s_i=\texttt{0}$ 或 $\texttt{1}$),描述游戏的初始状态。如果 $s_i=\texttt{1}$,表示妖精 $i$ 起初拿着土豆;否则,表示他们没有拿着土豆。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例的 $n$ 之和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print two integers — the scores of the Red Team and the Blue Team, respectively, if they play optimally.

对于每个测试用例,输出两个整数,分别表示红队和蓝队在双方都采用最优策略时的得分。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, it is optimal for leprechaun $1$ to pass the potato to leprechaun $2$ in the only round. Afterwards, only leprechaun $2$, who belongs to the Blue Team, holds a potato. Therefore, the score of the Red Team is $1$, while the score of the Blue Team is $0$.

在第一个测试用例中,最优策略是在唯一的一轮中让妖精 $1$ 把土豆传给妖精 $2$。之后,只有属于蓝队的妖精 $2$ 拿着土豆。因此,红队得分为 $1$,蓝队得分为 $0$。AI (CI翻译)

In the second test case, it is optimal for leprechaun $4$ to pass their potato to leprechaun $1$ in the only round. Note that leprechaun $3$ cannot pass their potato to leprechaun $4$, because leprechaun $4$ already holds a potato at the beginning of the round.

在第二个测试用例中,最优策略是在唯一的一轮中让妖精 $4$ 把土豆传给妖精 $1$。注意,妖精 $3$ 不能把土豆传给妖精 $4$,因为妖精 $4$ 在本轮开始时已经拿着土豆。AI (CI翻译)

Here is a demonstration for the third test case:

以下是第三个测试用例的演示:AI (CI翻译)

image

imageAI (CI翻译)

Note that this is one possible optimal strategy for both teams. Other optimal strategies may exist, but the resulting scores are the same.

注意,这是双方的一种最优策略。也可能存在其他最优策略,但最终得分相同。AI (CI翻译)

样例

Input #1
6
2 1
1000
2 1
0011
3 2
101110
5 100000
1111111111
5 100000
0000000000
7 4
10011110101011
Output #1
1 0
0 2
3 1
5 5
0 0
7 2
InputCopy OutputCopy
题目信息
题号
2255A
时间限制
2 s
内存限制
256 MB
标签
博弈论
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。