CF380D.Sereja and Cinema

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The cinema theater hall in Sereja's city is n seats lined up in front of one large screen. There are slots for personal possessions to the left and to the right of each seat. Any two adjacent seats have exactly one shared slot. The figure below shows the arrangement of seats and slots for n = 4.

Today it's the premiere of a movie called "Dry Hard". The tickets for all the seats have been sold. There is a very strict controller at the entrance to the theater, so all n people will come into the hall one by one. As soon as a person enters a cinema hall, he immediately (momentarily) takes his seat and occupies all empty slots to the left and to the right from him. If there are no empty slots, the man gets really upset and leaves.

People are not very constant, so it's hard to predict the order in which the viewers will enter the hall. For some seats, Sereja knows the number of the viewer (his number in the entering queue of the viewers) that will come and take this seat. For others, it can be any order.

Being a programmer and a mathematician, Sereja wonders: how many ways are there for the people to enter the hall, such that nobody gets upset? As the number can be quite large, print it modulo 1000000007 (109 + 7).

Sereja 所在城市的电影院放映厅内有 n 个座位,排成一列,正对着一块巨大的银幕。每个座位的左侧和右侧均设有供观众放置个人物品的置物槽。任意两个相邻座位之间恰好共享一个置物槽。下图展示了当 n = 4 时座位与置物槽的布局:

今天是电影《干硬》("Dry Hard")的首映式,所有座位的门票均已售出。影院入口处有一位极为严格的检票员,因此全部 n 名观众将依次、一人接一人地进入放映厅。每当一名观众进入放映厅,他便会立即(瞬时) 坐到自己的座位上,并占据其左侧和右侧所有尚未被占用的置物槽。若此时其左右两侧不存在任何空置的置物槽,该观众便会极度不满并离场。

观众的行为并不十分稳定,因此很难准确预测他们进入放映厅的顺序。对于某些座位,Sereja 已知将坐在该座位上的观众在入场队列中的编号(即其入场序号);而对于其余座位,观众的入场顺序则可以是任意的。

作为一名程序员兼数学家,Sereja 想知道:有多少种可能的入场顺序,使得没有任何观众因不满而离场?由于结果可能非常大,请输出其对 1000000007(即 109+710^9 + 7)取模后的值。

输入格式

The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers, the i-th integer shows either the index of the person (index in the entering queue) with the ticket for the i-th seat or a 0, if his index is not known. It is guaranteed that all positive numbers in the second line are distinct.

You can assume that the index of the person who enters the cinema hall is a unique integer from 1 to n. The person who has index 1 comes first to the hall, the person who has index 2 comes second and so on.

第一行包含一个整数 nn(1 ≤ n ≤ 1051 ≤ n ≤ 10^5)。第二行包含 nn 个整数,其中第 ii 个整数表示持有第 ii 个座位门票的人的编号(即其在入场队列中的序号),若该编号未知,则为 00。保证第二行中所有正整数互不相同。

你可以假设进入电影院大厅的人的编号是 11 到 nn 之间的唯一整数:编号为 11 的人最先入场,编号为 22 的人第二个入场,依此类推。

输出格式

In a single line print the remainder after dividing the answer by number 1000000007 (109 + 7).

在一行中输出答案对 10000000071000000007(即 109+710^9 + 7)取模后的余数。

输入输出样例

  • 输入#1

    11
    0 0 0 0 0 0 0 0 0 0 0

    输出#1

    1024
  • 输入#2

    6
    0 3 1 0 0 0

    输出#2

    3

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

首页