QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#384. 泳池

Statistics

久蓮係一個貪玩嘅女仔。

暑假終於到喇,久蓮決定請佢啲朋友嚟游水。佢打算先喺屋企嘅私人海灘外面,圈出一塊長方形海域做游泳場。不過,大海有各式各樣嘅危險,有啲地方水太深,有啲地方有帶毒嘅水母出沒。佢想圈出嚟呢塊海域全部都安全。

經過初步分析,佢將呢塊海域抽象成一個底邊長 $N$ 米、高 $1001$ 米嘅長方形網格。其中,網格嘅底邊對應佢屋企嘅私人海灘,每個 $1\times 1$ 嘅小正方形都代表一個單位海域。佢拜託爸爸聽日去量度每個小正方形係咪安全。知道呢啲資料之後,佢要做嘅就係圈出佢想要嘅游泳場。

佢心目中理想嘅游泳場要符合以下三個條件:

  • 一定要保證安全。即係游泳場入面每個單位海域都安全。
  • 一定要係矩形。即係游泳場一定要係成個網格入面一個 $a\times b$ 嘅子網格。
  • 一定要同海灘相鄰。即係游泳場嘅下邊界一定要緊貼網格嘅下邊界。

例如,當 $N=5$ 時,如果量度結果如下(因為 $1001$ 太大,呢度只畫出網格最下面三行嘅資料,其餘部分全部都危險)。

problem_384_01e06ee06d7433f5dd4c8e0566493d51.png

咁佢可以揀最下面一行嘅 $1\times 4$ 子海域,亦可以揀第三列嘅 $3\times 1$ 子海域。注意,佢唔可以揀最上面一行嘅 $1\times 5$ 子海域,因為嗰度冇同海灘相鄰。

為咗令朋友玩得開心,佢想令游泳場嘅面積盡量大。因此,佢會揀最下面嗰行嘅 $1\times 4$ 子海域做最後方案。

雖然佢要等到聽日先知每個單位海域係咪安全,但佢而家就想開始估計游泳場有幾大。經過簡單估計,佢假設每個單位海域都獨立地有 $q$ 嘅概率係安全嘅,有 $1-q$ 嘅概率係唔安全嘅。佢想知道,佢可以揀嘅最大游泳場嘅面積恰好係 $K$ 嘅概率係幾多。

不過久蓮對數學冇乜興趣,所以佢想請你幫佢計一計呢個數值。

輸入格式

由檔案 pool.in 讀入數據。

輸入一行四個正整數 $N,K,x,y$,其中 $1\le x<y<998244353$。$q$ 嘅值係 $\frac{x}{y}$。

輸出格式

輸出至檔案 pool.out。

輸出一行,一個整數,表示答案喺模 $998244353$ 意義之下嘅值。

即係設答案化成最簡分數之後係 $\frac{a}{b}$,其中 $a$ 同 $b$ 互質。輸出整數 $x$,令到 $bx\equiv a\pmod{998244353}$,而且 $0\le x<998244353$。可以證明,呢個整數 $x$ 係唯一嘅。

樣例

輸入格式 1

10 5 1 2

輸出格式 1

342025319

樣例 2

請睇選手目錄入面嘅 pool/pool2.in 同 pool/pool2.ans。

樣例 3

請睇選手目錄入面嘅 pool/pool3.in 同 pool/pool3.ans。

提示

$x^{p-1}\equiv 1\pmod p$,其中 $p$ 係質數,$x\in[1,p)$。

子任務

測試點編號 $N$ $K$
$1,2$ $=1$ $\le 1000$
$3$ $\le 10$ $\le 8$
$4$ $\le 10$ $\le 9$
$5$ $\le 10$ $\le 10$
$6$ $\le 1000$ $\le 7$
$7$ $\le 1000$ $\le 8$
$8$ $\le 1000$ $\le 9$
$9,10,11$ $\le 1000$ $\le 100$
$12,13,14$ $\le 1000$ $\le 1000$
$15,16$ $\le 10^9$ $\le 10$
$17,18$ $\le 10^9$ $\le 100$
$19,20$ $\le 10^9$ $\le 1000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.