[POI 2021/2022 R1] Impreza krasnali

Luogu
IDLGP9418
Time500ms
Memory256MB
DifficultyP5
POI(波兰)2021
有 $n$ 个人依次站成一排,每个人手上都有一个数字,这 $n$ 个数字形成一个排列。 每个人会二选一地报告他左边或右边的人手上的数字。注意第一个人与第 $n$ 个人并不相邻,所以第一个人总是会报告第二个人的数字,第 $n$ 个人总是会报告第 $n-1$ 个人的数字。 现在你得到了 $n$ 个人报告的数字,求出原先的排列有多少种可能。 ## Input 第一行一个正整数 $n$。 第二行 $n$ 个整数,表示每个人报告的数字。 ## Output 一行一个整数,你的答案模 $10^9+7$。 [samples] ## Background 译自 [XXIX Olimpiada Informatyczna – I etap](https://sio2.mimuw.edu.pl/c/oi29-1/dashboard/) [Impreza krasnali](https://sio2.mimuw.edu.pl/c/oi29-1/p/imp/)。 ## Note 对于所有数据,$2\leq n\leq 100000$。 | 子任务编号 | 附加限制 | 分数 | | :----------: | :----------: | :----------: | | 1 | $n\leq 10$ | 12 | | 2 | $n\leq 20$ | 30 | | 3 | $n\leq 1000$ | 30 | | 4 | | 28 |
Samples
Input #1
5
3 4 3 4 1
Output #1
2
Input #2
见附件
Output #2
0
Input #3
见附件
Output #3
1
API Response (JSON)
{
  "problem": {
    "name": "[POI 2021/2022 R1] Impreza krasnali",
    "description": {
      "content": "有 $n$ 个人依次站成一排,每个人手上都有一个数字,这 $n$ 个数字形成一个排列。 每个人会二选一地报告他左边或右边的人手上的数字。注意第一个人与第 $n$ 个人并不相邻,所以第一个人总是会报告第二个人的数字,第 $n$ 个人总是会报告第 $n-1$ 个人的数字。 现在你得到了 $n$ 个人报告的数字,求出原先的排列有多少种可能。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 500,
      "memory_limit": 262144
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP9418"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "有 $n$ 个人依次站成一排,每个人手上都有一个数字,这 $n$ 个数字形成一个排列。\n\n每个人会二选一地报告他左边或右边的人手上的数字。注意第一个人与第 $n$ 个人并不相邻,所以第一个人总是会报告第二个人的数字,第 $n$ 个人总是会报告第 $n-1$ 个人的数字。\n\n现在你得到了 $n$ 个人报告的数字,求出原先的排列有多少种可能。\n\n## Input\n\n第一行一个正整数 $n$。\n\n第二行...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments