NOI '17 P3 - Pool

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 3.0s
Memory limit: 512M

Problem types

There is a pool that can be modeled as a rectangular grid with width N meters and height 1001 meters. The bottom edge of the grid corresponds to a beach. Each 1m×1m square cell of the grid represents a unit of sea.

A safe area for swimming shall satisfy the following constraints:

  • All cells in the pool are safe.
  • Must be rectangular.
  • Must be adjacent to the bottom edge (i.e. the beach).

Given that each square cell of 1m×1m has probability q to be safe (independently), and 1q probability to be not safe, find the probability such that the largest safe area for swimming is exactly K.

Input Specification

Input a line with four positive integers N,K,x,y where 1x<y<998244353. The parameter q is just xy.

Output Specification

Output a line with an integer denoting the answer modulo 998244353: if the answer is ab in reduced form (i.e. a and b are coprime), then output x such that bxamod998244353 and 0x<998244353.

Input

Copy
10 5 1 2

Output

Copy
342025319

Hint

xp11modp where p is prime and x[1,p).

Constraints

Test caseNK
1,2=11000
3108
49
510
610007
78
89
9,10,11100
12,13,141000
15,1610910
17,18100
19,201000

Comments

There are no comments at the moment.