CF1091H.New Year and the Tricolore Recreation
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob play a game on a grid with n rows and infinitely many columns. In each row, there are three tokens, blue, white and red one. Before the game starts and after every move, the following two conditions must hold:
- Any two tokens are not in the same cell.
- In each row, the blue token is to the left of the white token, and the red token is to the right of the white token.
First, they pick a positive integer f, whose value is valid for the whole game. Second, the starting player is chosen and makes his or her first turn. Then players take alternating turns. The player who is unable to make a move loses.
During a move, a player first selects an integer k that is either a prime number or a product of two (not necessarily distinct) primes. The smallest possible values of k are thus 2,3,4,5,6,7,9,10,11,13,14,15,17,19,…. Furthermore, k must not be equal to the previously picked integer f. Each turn, a move is performed in exactly one of the rows.
If it is Alice's turn, she chooses a single blue token and moves it k cells to the right. Alternatively, she may move both the blue and the white token in the same row by the same amount k to the right.
On the other hand, Bob selects a single red token and moves it k cells to the left. Similarly, he may also move the white and the red token in the corresponding row by k to the left.
Note that Alice may never move a red token, while Bob may never move a blue one. Remember that after a move, the two conditions on relative positions of the tokens must still hold.
Both players play optimally. Given the initial state of the board, determine who wins for two games: if Alice starts and if Bob starts.
爱丽丝和鲍勃在一个具有 n 行、无限多列的网格上进行一场游戏。在每一行中,均有三枚棋子:一枚蓝色、一枚白色和一枚红色。游戏开始前及每次移动后,以下两个条件必须始终满足:
- 任意两枚棋子不能位于同一格子中;
- 在每一行中,蓝色棋子位于白色棋子左侧,红色棋子位于白色棋子右侧。
首先,双方共同选定一个正整数 f,该值在整个游戏中保持不变。其次,确定先手玩家并由其进行首次操作。随后双方轮流操作。无法进行合法操作的玩家判负。
在一次操作中,玩家首先选择一个整数 k,该整数必须为素数,或为两个(不一定互异)素数的乘积。因此,k 的最小可能取值依次为 2,3,4,5,6,7,9,10,11,13,14,15,17,19,…。此外,k 不得等于之前选定的整数 f。每次操作仅在恰好一行中执行。
若轮到爱丽丝操作,她可选择某一行中的单枚蓝色棋子,将其向右移动 k 格;或者,她也可选择同一行中的蓝色与白色棋子,将二者同时向右移动 k 格。
而鲍勃则选择某一行中的单枚红色棋子,将其向左移动 k 格;或者,他亦可选择同一行中的白色与红色棋子,将二者同时向左移动 k 格。
注意:爱丽丝永远不可移动红色棋子,鲍勃也永远不可移动蓝色棋子。此外,请牢记:每次移动后,上述关于棋子相对位置的两个条件仍须严格满足。
双方均以最优策略进行游戏。给定棋盘的初始状态,请分别判断在两种情形下谁获胜:一是爱丽丝先手;二是鲍勃先手。
输入格式
The first line contains a two integers n and f (1≤n≤105, 2≤f≤2⋅105) — the number of rows and the forbidden move, respectively.
Each of the next n lines contains three integers bi, wi, ri (−105≤bi<wi<ri≤105) — the number of column in which the blue, white and red token lies in the i-th row, respectively.
第一行包含两个整数 n 和 f(1≤n≤105,2≤f≤2⋅105)—— 分别表示行数和禁止移动步长。
接下来的 n 行中,每行包含三个整数 bi、wi、ri(−105≤bi<wi<ri≤105)—— 分别表示第 i 行中蓝色、白色和红色棋子所在的列号。
输出格式
Output two lines.
The first line should contain the name of the winner when Alice starts, and the second line should contain the name of the winner when Bob starts.
输出两行。
第一行应包含当 Alice 先手时的获胜者姓名,第二行应包含当 Bob 先手时的获胜者姓名。
输入输出样例
输入#1
1 6 0 3 9
输出#1
Alice Bob
输入#2
1 2 0 3 9
输出#2
Alice Bob
输入#3
10 133 -248 -193 -187 97 101 202 -72 67 91 23 89 215 -129 -108 232 -223 -59 236 -99 86 242 -137 -109 -45 -105 173 246 -44 228 243
输出#3
Bob Alice
说明/提示
The first example is as follows:
When Alice starts, she can win by moving the blue and white token to right by 2 cells, getting into position 2 5 9. Regardless of what Bob does, Alice will have one more move and then the game is over. For instance, he can move both the red and white token by 2 cells to the left, reaching state 2 3 7. Alice can then move blue and white token by 2 to move into 4 5 7, where no more moves are possible.
If Bob starts, he gains enough advantage to win. For instance, he may move the red token by 3 to the left, getting into position 0 3 6. Alice can, for example, move the blue token by 2, which is countered by Bob by moving the red token by 2. The game ends in position 2 3 4.
In the second example, it is forbidden to move by 2, but this doesn't stop Alice from winning! She can move the blue and white token by 4, getting into position 4 7 9. Now Bob has no move, since moving by 2 is forbidden.
第一个例子如下:
当爱丽丝先手时,她可以通过将蓝色和白色棋子同时向右移动 2 格,到达位置 2 5 9 来获胜。无论鲍勃如何应对,爱丽丝都还能再走一步,随后游戏结束。例如,鲍勃可以将红色和白色棋子同时向左移动 2 格,到达状态 2 3 7;此时爱丽丝可将蓝色和白色棋子同时向右移动 2 格,进入 4 5 7,该状态下已无法进行任何合法移动。
若鲍勃先手,则他能获得足够优势以获胜。例如,他可将红色棋子向左移动 3 格,到达位置 0 3 6;爱丽丝可能(例如)将蓝色棋子向右移动 2 格,但鲍勃随即通过将红色棋子向右移动 2 格予以回应;最终游戏在位置 2 3 4 结束。
在第二个例子中,禁止以步长 2 移动,但这并不妨碍爱丽丝获胜!她可以将蓝色和白色棋子同时以步长 4 移动,到达位置 4 7 9;此时鲍勃无法行动,因为步长 2 的移动已被禁止。
输入解题思路,AI测评打分。不知道怎么写?