#4639. Chinese Restaurant

0
    ID: 4639 传统题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 2 上传者: 标签>AtCoderabc268CGESP 5级前缀和枚举(单层循环)

Chinese Restaurant

Chinese Restaurant

题目描述

Person 00, Person 11, …\ldots, and Person (N−1)(N-1) are sitting around a turntable in their counterclockwise order, evenly spaced. Dish pip_i is in front of Person ii on the table.
You may perform the following operation 00 or more times:

Rotate the turntable by one NN-th of a counterclockwise turn. As a result, the dish that was in front of Person ii right before the rotation is now in front of Person (i+1) mod N(i+1) \bmod N.

When you are finished, Person ii is happy if Dish ii is in front of Person (i−1) mod N(i-1) \bmod N, Person ii, or Person (i+1) mod N(i+1) \bmod N.
Find the maximum possible number of happy people.

What is $a \bmod m$? For an integer $a$ and a positive integer $m$, $a \bmod m$ denotes the integer $x$ between $0$ and $(m-1)$ (inclusive) such that $(a-x)$ is a multiple of $m$. (It can be proved that such $x$ is unique.)

输入格式

Input is given from Standard Input in the following format: NN p0p_0 …\ldots pN−1p_{N-1}

输出格式

Print the answer.

4
1 2 0 3
4
3
0 1 2
3
10
3 9 6 1 7 2 8 0 5 4
5

提示

3≤N≤2×1053 \leq N \leq 2 \times 10^5 0≤pi≤N−10 \leq p_i \leq N-1 pi≠pjp_i \neq p_j if i≠ji \neq j. All values in input are integers.下面的图显示了一次操作之后的桌面情形。 在这里,有四位满足的人:

Person 00 因为 Dish 00 在 Person 3 (=(0−1) mod 4)3\ (=(0-1) \bmod 4) 面前而感到满足; Person 11 因为 Dish 11 在 Person 1 (=1)1\ (=1) 面前而感到满足; Person 22 因为 Dish 22 在 Person 2 (=2)2\ (=2) 面前而感到满足; Person 33 因为 Dish 33 在 Person 0 (=(3+1) mod 4)0\ (=(3+1) \bmod 4) 面前而感到满足。

不可能有五位或更多满足的人,所以答案是 44。

标签: AtCoder|abc268C

来源

AtCoder|abc268C