QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 512 MB 總分: 100

#9782. 非零前缀后缀和

统计

计算满足以下条件的整数数组 $[a_1, a_2, \dots, a_n]$ 的数量:

  1. 对于所有 $1 \le i \le n$,满足 $|a_i| \le m$。
  2. 存在数组 $a$ 的一个排列 $[b_1, b_2, \dots, b_n]$,使得以下条件成立:
    • 对于所有 $1 \le k \le n$,满足 $b_1 + b_2 + \dots + b_k \neq 0$。
    • 对于所有 $1 \le k \le n$,满足 $b_k + b_{k+1} + \dots + b_n \neq 0$。

输出答案对 $p$ 取模的结果,其中 $p$ 是一个大素数。

输入格式

输入仅一行,包含三个整数 $n, m, p$。

约束条件

$2 \le n \le 100$ $1 \le m \le 100$ $10^8 < p < 10^9$,$p$ 为素数。

输出格式

输出一个整数,即答案对 $p$ 取模的结果。

样例

输入格式 1

2 1 998244353

输出格式 1

2

说明

在第一个测试用例中,共有 9 个可能的数组:$[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]$。只有数组 $[-1, -1]$ 和 $[1, 1]$ 满足题目中的条件。

输入格式 2

69 42 696969697

输出格式 2

378553557

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.