欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1033C.Permutation Game
Permutation Game
After a long day, Alice and Bob decided to play a little game. The game board consists of cells in a straight line, numbered from to , where each cell contains a number between and . 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 to cell only if the following two conditions are satisfied:
- the number in the new cell must be strictly larger than the number in the old cell (i.e. ), and
- the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. ).
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.
Input
The first line contains a single integer () — the number of numbers.
The second line contains integers (). Furthermore, there are no pair of indices such that .
Output
Print — a string of characters, where the -th character represents the outcome of the game if the token is initially placed in the cell . If Alice wins, then has to be equal to "A"; otherwise, has to be equal to "B".
Note
In the first sample, if Bob puts the token on the number (not position):
- : Alice can move to any number. She can win by picking , from which Bob has no move.
- : Alice can move to and . Upon moving to , Bob can win by moving to . If she chooses instead, she wins, as Bob has only a move to , from which Alice can move to .
- : Alice can only move to , after which Bob wins by moving to .
- , , or : Alice wins by moving to .
- , : Alice has no move, and hence she loses immediately.
Samples
8
3 6 5 4 2 7 1 8
BAAAABAB
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
ABAAAABBBAABAAB
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |