CF2203D.Divisibility Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing a game. They have an array aa of nn elements and an array bb of mm elements.

The players take turns. Alice goes first. On their turn, each player chooses a number xx from array aa and a number yy from array bb. Alice has her own rule for choosing xx and yy, and Bob has his:

  • Alice must choose xx and yy such that yy is divisible by xx.
  • Bob must choose xx and yy such that yy is not divisible by xx.

After choosing xx and yy, yy is removed from the array bb (but xx remains in aa). When yy is removed from bb, if there are multiple occurrences of yy, only one is removed. The player who cannot make a move loses.

Who will win if both players play optimally?

爱丽丝和鲍勃正在玩一个游戏。他们有一个包含 nn 个元素的数组 aa 和一个包含 mm 个元素的数组 bb。

两名玩家轮流进行操作,爱丽丝先手。在每一轮中,每位玩家需从数组 aa 中选择一个数 xx,并从数组 bb 中选择一个数 yy。爱丽丝和鲍勃各自遵循不同的选择规则:

  • 爱丽丝必须选择满足 yy 被 xx 整除(即 x∣yx \mid y)的 xx 和 yy;
  • 鲍勃必须选择满足 yy 不被 xx 整除(即 x∤yx \nmid y)的 xx 和 yy。

选定 xx 和 yy 后,yy 将从数组 bb 中被移除(但 xx 仍保留在 aa 中)。当 yy 从 bb 中被移除时,若 yy 在 bb 中出现多次,则仅移除其中一个。无法进行合法操作的玩家判负。

若双方均以最优策略进行游戏,谁将获胜?

输入格式

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

The first line of each test case contains two integers nn and mm (1≤n,m≤1061 \le n, m \le 10^{6}).

The second line of each test case contains nn integers aia_{i} (1≤ai≤n+m1 \le a_{i} \le n + m) — the elements of the array aa.

The last line of each test case contains mm integers bib_{i} (1≤bi≤n+m1 \le b_{i} \le n + m) — the elements of the array bb.

Additional constraints on the input:

  • the sum of nn over all test cases does not exceed 10610^6;
  • the sum of mm over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤1061 \le n, m \le 10^{6})。

每个测试用例的第二行包含 nn 个整数 aia_{i}(1≤ai≤n+m1 \le a_{i} \le n + m)——即数组 aa 的元素。

每个测试用例的最后一行包含 mm 个整数 bib_{i}(1≤bi≤n+m1 \le b_{i} \le n + m)——即数组 bb 的元素。

输入的额外约束条件:

  • 所有测试用例中 nn 的总和不超过 10610^6;
  • 所有测试用例中 mm 的总和不超过 10610^6。

输出格式

For each test case, print one word:

  • Alice if Alice wins;
  • Bob if Bob wins.

对于每个测试用例,输出一个单词:

  • 若 Alice 获胜,输出 Alice;
  • 若 Bob 获胜,输出 Bob。

输入输出样例

  • 输入#1

    3
    9 3
    3 2 4 2 2 4 4 2 4
    6 7 12
    10 3
    3 2 5 4 2 5 3 4 4 4
    10 7 13
    1 5
    1
    1 2 3 4 5

    输出#1

    Alice
    Bob
    Alice

说明/提示

Consider the first test case. Let's show how Alice wins through the moves:

  • Alice's move: x=3,y=6x = 3, y = 6 (after this, 66 will be removed from bb, resulting in b=[7,12]b = [7, 12])
  • Bob's move: x=3,y=7x = 3, y = 7 (Bob will choose y=7y = 7 on his turn anyway, since there is no xx that does not divide y=12y = 12, after this move b=[12]b = [12])
  • Alice's move: x=4,y=12x = 4, y = 12 (after this move, bb becomes empty)
  • Bob's move: Bob loses, as he cannot make a move

考虑第一个测试用例。下面展示爱丽丝(Alice)如何通过以下操作获胜:

  • 爱丽丝的操作:x=3,y=6x = 3, y = 6(此后,66 将从 bb 中被移除,得到 b=[7,12]b = [7, 12])
  • 鲍勃(Bob)的操作:x=3,y=7x = 3, y = 7(鲍勃在本轮中必然选择 y=7y = 7,因为此时不存在能整除 y=12y = 12 的 xx;此操作后 b=[12]b = [12])
  • 爱丽丝的操作:x=4,y=12x = 4, y = 12(此操作后,bb 变为空集)
  • 鲍勃的操作:鲍勃失败,因为他无法进行任何操作

输入解题思路,AI测评打分。不知道怎么写?

首页