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

32461번 - Automata Embedding 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB (추가 메모리 없음)271010100.000%

문제

For a string $S$ of length $n,ドル let $S[a..b]$ denote the substring consisting of the characters from position $a$ to position $b$ (where 1ドル\leq a\leq b\leq n$). Also, the failure function $f:[0,n]\rightarrow[0 , n-1]$ of $S$ is defined as follows.

\[f(i) =\max(\{0\}\cup\{j,円\vert,円 S[1..j] =S[i-j+1..i] ,,円 1\leq j<i\})\]

The KMP automaton made using the failure function of string $S$ denotes the following kind of automaton. The automaton has $n+1$ states $[0..n],ドル and for each state 0ドル\leq i\leq n,ドル there exists exactly one transition from $i$ to $f(i)$.

If a KMP automaton can be embedded on a plane, it means that if we map state $i$ to a point at $(i,0)$ on the plane, and draw all transitions $i\rightarrow f(i)$ as arrows which do not cross the $x$-axis on the plane, it is possible to draw all $n+1$ arrows such that no arrows intersect except when they meet at endpoints.

Using an alphabet consisting of $C$ letters, find the number of strings of length $n$ whose KMP automaton can be embedded on a plane modulo 998ドル,円 244,円 353$.

KMP automaton for the string $S = abab$

입력

The first line of input contains two space-separated integers $n$ and $C,ドル denoting the length of the string and the number of letters in the alphabet respectively.

출력

The first line of output should contain the number of strings of length $n$ whose KMP automaton can be embedded on a plane modulo 998ドル,円 244,円 353$.

제한

  • 1ドル\leq n\leq 10^{18}$
  • 1ドル\leq C\leq 10^{9}$

예제 입력 1

3 3

예제 출력 1

27

예제 입력 2

1000000000000000000 1000000000

예제 출력 2

609226805

노트

출처

University > KAIST > KAIST ICPC Mock Competition > 2024 KAIST 14th ICPC Mock Competition A번

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

출처

대학교 대회

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

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