QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 100

#9761. 行军令

统计

Bob Roberts 院长负责安排学院教授在毕业典礼上的入场顺序。由于来自新成立的 DEI 研究部门的一些教授提出了投诉,学院决定教授们的入场顺序不应基于资历,而应是随机的。Bob 认为这很好,为了完全透明,他公布了自己用来创建入场名单的方法:他从一个包含 $n$ 名教授(编号为 $0, 1, \dots, n-1$)的按字母顺序排列的名单和一个非负整数 $m < 10^9$ 开始。入场名单中的第一个人是字母名单中位置为 $m \bmod n$ 的人。这会使字母名单缩短一人,并将所有位置大于 $m \bmod n$ 的人向前移动。入场名单中的第二个人是位置为 $m \bmod (n-1)$ 的人,依此类推。

例如,假设有 6 名教授 A、B、C、D、E 和 F。如果 $m = 11679$,则入场名单的创建过程如下:

$n$ $m \bmod n$ 字母名单 入场名单
6 3 A B C D E F D
5 4 A B C E F D F
4 3 A B C E D F E
3 0 A B C D F E A
2 1 B C D F E A C
1 0 B D F E A C B

这听起来很公平,但并不像一些教授所希望的那样透明,因为 Bob 院长并没有公开他所使用的 $m$ 值。这使得人们很难确定他是否真的遵循了他所说的方法,还是仅仅根据个人的喜好和偏见选择了入场顺序。教职员工想知道的是,对于给定的入场顺序,是否存在一个 $m$ 值可以产生该顺序?

输入格式

第一行包含一个十进制整数 $n$ ($5 \le n \le 20$),表示将要入场的教授人数。第二行包含一个字符串,由前 $n$ 个大写字母的排列组成,给出了提议的入场顺序。

输出格式

如果给定的入场顺序不能由该算法产生,则输出一行,包含单词 NO。否则,输出两行,第一行包含单词 YES,第二行包含可以产生该入场顺序的最小非负整数 $m$。

样例

输入格式 1

6
DFEACB

输出格式 1

YES
39

输入格式 2

7
DFEGACB

输出格式 2

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.