Logo
(追記) (追記ここまで)

25659번 - Counting Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
16 초 (추가 시간 없음) 1024 MB222100.000%

문제

We are given integers $n$ and $c$.

A sequence $a_1, a_2, \ldots, a_m$ is good if and only if:

  • $a_i > 0$ for all 1ドル \leq i \leq m,ドル
  • $|a_{i+1}-a_i|=1$ for all 1ドル \leq i \leq m-1,ドル
  • $\sum_{i=1}^m a_i=n$.

For a good integer sequence $a_1, a_2, \ldots, a_m,ドル let us define

$$f(a) = \sum_{i=1}^{m-1} [a_i > a_{i+1}]\text{.}$$

That is, $f(a)$ denotes the number of indices $i$ that satisfy $a_i > a_{i+1}$ among all 1ドル \leq i \leq m - 1$. We define the weight of the sequence $a$ as the value of $c^{f(a)}$.

Your task is to calculate the sum of the weights of all good sequences, modulo 998ドル,244円,353円$.

입력

The first line contains two integers $n$ and $c$ (1ドル \le n \le 3 \cdot 10^5,ドル 0ドル \leq c < 998,244円,353円$).

출력

Output the answer modulo 998ドル,244円,353円$.

제한

예제 입력 1

5 3

예제 출력 1

8

예제 입력 2

1 0

예제 출력 2

1

예제 입력 3

2022 39

예제 출력 3

273239559

힌트

In the first example, all good sequences are as follows:

$a$ $f(a)$ $c^{f(a)}$
$[5]$ 0ドル$ 1ドル$
$[2, 3]$ 0ドル$ 1ドル$
$[3, 2]$ 1ドル$ 3ドル$
$[2, 1, 2]$ 1ドル$ 3ドル$

So the answer is 1ドル + 1 + 3 + 3 = 8$.

출처

Camp > Petrozavodsk Programming Camp > Summer 2022 > Day 3: Qingyu, flower and their friends’ Contest C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /