CF1033C.Permutation Game

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After a long day, Alice and Bob decided to play a little game. The game board consists of nn cells in a straight line, numbered from 11 to nn, where each cell contains a number aia_i between 11 and nn. Furthermore, no two cells contain the same number.

A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell ii to cell jj only if the following two conditions are satisfied:

  • the number in the new cell jj must be strictly larger than the number in the old cell ii (i.e. aj>aia_j \gt a_i), and
  • the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. ∣i−j∣ mod ai=0|i-j|\bmod a_i = 0).

Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.

经过漫长的一天后,Alice 和 Bob 决定玩一个小游戏。游戏棋盘由一行 nn 个格子组成,编号从 11 到 nn,每个格子中包含一个介于 11 到 nn 之间的整数 aia_i。此外,任意两个格子中的数字互不相同。

一个棋子被放置在某个格子中。他们轮流移动该棋子,Alice 先手。当前玩家可以从格子 ii 移动到格子 jj,当且仅当满足以下两个条件:

  • 新格子 jj 中的数字必须严格大于旧格子 ii 中的数字(即 aj>aia_j > a_i),且
  • 本次移动的距离必须是旧格子中数字的倍数(即 ∣i−j∣ mod ai=0|i-j| \bmod a_i = 0)。

无法进行合法移动的一方判负。对每个可能的起始位置,请判断若双方均以最优策略进行游戏,谁将获胜。可以证明该游戏总是有限的,即总有一方存在必胜策略。

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the number of numbers.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n). Furthermore, there are no pair of indices i≠ji \neq j such that ai=aja_i = a_j.

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 数字的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)。此外,不存在满足 ai=aja_i = a_j 的下标对 i≠ji \neq j。

输出格式

Print ss — a string of nn characters, where the ii-th character represents the outcome of the game if the token is initially placed in the cell ii. If Alice wins, then sis_i has to be equal to "A"; otherwise, sis_i has to be equal to "B".

输出字符串 ss —— 一个长度为 nn 的字符串,其中第 ii 个字符表示当棋子初始放置在第 ii 个格子时游戏的结果:若爱丽丝获胜,则 sis_i 应为 "A";否则 sis_i 应为 "B"。

输入输出样例

  • 输入#1

    8
    3 6 5 4 2 7 1 8

    输出#1

    BAAAABAB
  • 输入#2

    15
    3 11 2 5 10 9 7 13 15 8 4 12 6 1 14

    输出#2

    ABAAAABBBAABAAB

说明/提示

In the first sample, if Bob puts the token on the number (not position):

  • 11: Alice can move to any number. She can win by picking 77, from which Bob has no move.
  • 22: Alice can move to 33 and 55. Upon moving to 55, Bob can win by moving to 88. If she chooses 33 instead, she wins, as Bob has only a move to 44, from which Alice can move to 88.
  • 33: Alice can only move to 44, after which Bob wins by moving to 88.
  • 44, 55, or 66: Alice wins by moving to 88.
  • 77, 88: Alice has no move, and hence she loses immediately.

在第一个样例中,如果 Bob 将棋子放在某个数字(而非位置)上:

  • 11:Alice 可以移动到任意数字。她可以选择 77,此时 Bob 无法移动,从而获胜。
  • 22:Alice 可以移动到 33 或 55。若她移动到 55,则 Bob 可通过移动到 88 获胜;若她改为移动到 33,则她获胜,因为 Bob 此时只能移动到 44,而 Alice 接着可从 44 移动到 88。
  • 33:Alice 只能移动到 44,随后 Bob 通过移动到 88 获胜。
  • 44、55 或 66:Alice 通过移动到 88 获胜。
  • 77、88:Alice 无法移动,因此立即失败。

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

首页