問題一覧 > 教育的問題

No.2394 Sum of Subsequence-Sum Powers

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 110
作問者 : 👑 p-adic / テスター : hotman78 hiro1729
お気に入りにしたユーザー ProblemId : 8880 / 自分の提出
問題文最終更新日: 2023-07-26 16:37:34
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 399 (順位表) の他の問題:

Problem Statement

You are given three positive integers $N, M, B$ and a sequence $A$ of $N$ positive integers as input.

 

First, we introduce some notation. Let $S(A)$ be the set of all subsequences of $A$ (not necessarily contiguous).

Here, a subsequence also includes the data of which positions of $A$ its elements were taken from.

For example, when $A = (1,1,2)$, $A$ has $2$ subsequences that are $(1,2)$ as sequences, and they are distinguished from each other.

For each subsequence $A'$ of $A$, let $s(A')$ be the sum of its elements.

 

Find the remainder when $\sum_{A' \in S(A)} M^{s(A')}$ is divided by $B$.

Input

The input is given from standard input in $2$ lines in the following format:

$N$ $M$ $B$
$A$
  • Line $1$ contains $N, M, B$, separated by single-byte spaces.
  • Line $2$ contains the elements of $A$, separated by single-byte spaces.

Constraints

The input satisfies the following constraints:

  • $N$ is an integer satisfying $1 \leq N \leq 10^5$
  • $M$ is an integer satisfying $1 \leq M \leq 10^{18}$
  • $B$ is an integer satisfying $1 \leq B \leq 10^9$
  • Each element $a$ of $A$ is an integer satisfying $1 \leq a \leq 10^{18}$

Output

Print the remainder when $\sum_{A' \in S(A)} M^{s(A')}$ is divided by $B$ on $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
1 1 2
1
Output
0

$A = (1)$ has $2$ subsequences: the subsequence $A'_0$, which as a sequence is the empty sequence $()$, and the subsequence $A'_1$, which as a sequence is $(1)$.

$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} = 1^0 + 1^1 = 1 + 1 = 2 $

and the remainder when $2$ is divided by $B = 2$ is $0$.

Sample 2
Input
1 2 2
1
Output
1

$A$ is the same as in Sample 1. Using the same notation as in Sample 1, we have

$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} = 2^0 + 2^1 = 1 + 2 = 3 $

and the remainder when $3$ is divided by $B = 2$ is $1$.

Sample 3
Input
2 1 2
1 3
Output
0

$A = (1,3)$ has $4$ subsequences: the subsequence $A'_0$, which as a sequence is the empty sequence $()$, the subsequence $A'_1$, which as a sequence is $(1)$, the subsequence $A'_2$, which as a sequence is $(3)$, and the subsequence $A'_3$, which as a sequence is $(1,3)$.

$\displaystyle \sum_{A' \in S(A)} M^{s(A')} = M^{s(A'_0)} + M^{s(A'_1)} + M^{s(A'_2)} + M^{s(A'_3)} = 1^0 + 1^1 + 1^3 + 1^4 = 1 + 1 + 1 + 1 = 4 $

and the remainder when $4$ is divided by $B = 2$ is $0$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。