結果

問題 No.2230 Good Omen of White Lotus
ユーザー wolgnikwolgnik
提出日時 2023-02-24 22:48:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 107,804 KB
最終ジャッジ日時 2023-10-11 06:40:05
合計ジャッジ時間 14,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,920 KB
testcase_01 AC 73 ms
71,140 KB
testcase_02 AC 74 ms
70,872 KB
testcase_03 AC 74 ms
70,904 KB
testcase_04 AC 74 ms
71,056 KB
testcase_05 AC 74 ms
70,912 KB
testcase_06 AC 74 ms
70,956 KB
testcase_07 AC 73 ms
70,996 KB
testcase_08 WA -
testcase_09 AC 73 ms
71,084 KB
testcase_10 WA -
testcase_11 AC 72 ms
71,048 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 92 ms
75,860 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 94 ms
83,356 KB
testcase_25 AC 93 ms
83,444 KB
testcase_26 AC 95 ms
83,220 KB
testcase_27 AC 266 ms
107,612 KB
testcase_28 AC 254 ms
104,352 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 339 ms
105,648 KB
testcase_32 AC 294 ms
105,292 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 281 ms
93,488 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 378 ms
92,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
H, W, N, P = map(int, input().split())
mod = 998244353
a = [[] for _ in range(H + 1)]

for _ in range(N):
  x, y = map(int, input().split())
  a[x].append(y)

class SegTree:
  def segfunc(self, x, y):
    return max(x, y)
  def __init__(self, n, ide_ele, init_val):
    #####単位元######
    self.ide_ele = ide_ele
    #num:n以上の最小の2のべき乗
    self.num = 2 ** (n - 1).bit_length()
    self.seg = [self.ide_ele] * 2 * self.num
    #set_val
    for i in range(n):
      self.seg[i + self.num - 1] = init_val[i]    
    #built
    for i in range(self.num - 2, -1, -1) :
      self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
  def update(self, k, x):
    k += self.num - 1
    self.seg[k] = x
    while k + 1:
      k = (k - 1) // 2
      self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) 
  def query(self, p, q):
    if q <= p:
      return self.ide_ele
    p += self.num - 1
    q += self.num - 2
    res = self.ide_ele
    while q - p > 1:
      if p & 1 == 0:
        res = self.segfunc(res, self.seg[p])
      if q & 1 == 1:
        res = self.segfunc(res, self.seg[q])
        q -= 1
      p = p // 2
      q = (q - 1) // 2
    if p == q:
      res = self.segfunc(res, self.seg[p])
    else:
      res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
    return res

seg = SegTree(W + 1, 0, [0] * (W + 1))

for x in range(H, -1, -1):
  s = []
  a[x].sort(reverse = True)
  for y in a[x]:
    q = seg.query(y, W + 1)
    s.append((y, q + 1))
  for y, upd in s: seg.update(y, upd)

  #print(s)
q = seg.query(0, W + 1)
res = pow(P - 2, q, mod) * pow(P, (mod - 2) * q, mod)
res %= mod
res *= pow(P - 1, (H + W - 3 - q), mod) * pow(P, (mod - 2) * (H + W - 3 - q), mod)
res %= mod
res = 1 - res
res %= mod
print(res)
0