Universal Cup Judging System

Universal Cup

Süre Sınırı: 4.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

問題文

正整数 $N$、素数 $P$、および各要素が $P$ 未満である長さ $N$ の正整数列 $A = (A_1, A_2, \dots, A_N)$ が与えられます。$S = \{1, 2, \dots, N\}$ とします。

以下の条件をすべて満たす長さ $1$ 以上の集合の列 $T$ の個数を求め、結果を $P$ で割った余りを出力してください。

  • $T$ の各要素は $S$ の空でない部分集合である。
  • 各 $i = 1, 2, \dots, N$ について、次が成り立つ:
    • $T$ の要素のうち、ちょうど $A_i$ 個が $i$ を含む。

入力

入力は以下の形式で与えられます。

N P
A_1 A_2 ... A_N
  • $1 \le N \le 2 \times 10^5$
  • $113 \le P \le 500009$
  • $P$ は素数である
  • $1 \le A_i < P$ ($1 \le i \le N$)
  • 入力される値はすべて整数である

出力

答えを出力してください。

入出力例

2 113
1 2
5
4 8191
7 6 3 8
4477

注記

1 番目の例では、条件を満たす列 $T$ は $(\{1, 2\}, \{2\})$、$(\{2\}, \{1, 2\})$、$(\{1\}, \{2\}, \{2\})$、$(\{2\}, \{1\}, \{2\})$、$(\{2\}, \{2\}, \{1\})$ の計 $5$ 個です。

2 番目の例では、条件を満たす列 $T$ の個数を $P$ で割った余りを求めることを忘れないでください。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1492EditorialOpen题解jianglyView

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.