Sharing Bread

시간 제한2초메모리 제한1024 MB

요약
M명의 사람이 오른쪽으로 탐색해 빵을 하나씩 가져갈 수 있도록 하는 시작 토스터 수열의 개수를 998244353으로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
조합론, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

There are NN toasters, numbered from 11 to NN, from left to right. Initially, each toaster has a single piece of bread in it. There are MM people, numbered from 11 to MM, who are one by one looking for bread among the toasters, starting from person 11, person 22, and so on.

Person ii starts looking from toaster a_ia\_i (1≤a_i≤N1 ≤ a\_i ≤ N) and keeps going right until they found a toaster with a piece of bread in it. In other words, person ii is looking for the smallest jj such that a_i≤j≤Na\_i ≤ j ≤ N and toaster jj contains bread. If such a toaster exists, then person ii will take the bread from that toaster and leave; the toaster becomes empty afterward. If such a toaster does not exist, then person ii will leave empty-handed.

A starting sequence (a_1,a_2,⋯ ,a_M)(a\_1, a\_2, \cdots , a\_M) is fair if person ii starts looking from toaster ai and does not leave empty-handed, for all 1≤i≤M1 ≤ i ≤ M. Out of all NMN^M possible starting sequences, determine how many of them are fair modulo 998,244,353998\\, 244\\, 353.

입력

Input consists of two integers NN MM (1≤M≤N≤200,0001 ≤ M ≤ N ≤ 200\\, 000) in a single line representing the number of toasters and the number of people, respectively.

출력

Output an integer in a single line representing the number of fair starting sequence modulo 998,244,353998\\, 244\\, 353.

예제3

  1. 예제 1

    입력
    4 3
    
    예상 출력
    50
    
  2. 예제 2

    입력
    10 1
    
    예상 출력
    10
    
  3. 예제 3

    입력
    2 2
    
    예상 출력
    3