結果

問題 No.2230 Good Omen of White Lotus
ユーザー AngrySadEightAngrySadEight
提出日時 2022-12-11 23:26:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,022 ms / 2,000 ms
コード長 1,883 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 158,976 KB
最終ジャッジ日時 2023-09-27 12:34:23
合計ジャッジ時間 19,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
80,424 KB
testcase_01 AC 82 ms
80,396 KB
testcase_02 AC 84 ms
80,400 KB
testcase_03 AC 86 ms
80,244 KB
testcase_04 AC 83 ms
80,420 KB
testcase_05 AC 85 ms
80,388 KB
testcase_06 AC 83 ms
80,388 KB
testcase_07 AC 84 ms
80,632 KB
testcase_08 AC 83 ms
80,588 KB
testcase_09 AC 86 ms
80,280 KB
testcase_10 AC 84 ms
80,396 KB
testcase_11 AC 81 ms
80,460 KB
testcase_12 AC 84 ms
80,416 KB
testcase_13 AC 92 ms
81,128 KB
testcase_14 AC 320 ms
96,140 KB
testcase_15 AC 96 ms
81,360 KB
testcase_16 AC 307 ms
105,580 KB
testcase_17 AC 320 ms
105,564 KB
testcase_18 AC 310 ms
105,744 KB
testcase_19 AC 311 ms
105,780 KB
testcase_20 AC 138 ms
83,904 KB
testcase_21 AC 119 ms
82,692 KB
testcase_22 AC 141 ms
84,184 KB
testcase_23 AC 149 ms
84,352 KB
testcase_24 AC 82 ms
80,416 KB
testcase_25 AC 82 ms
80,396 KB
testcase_26 AC 83 ms
80,508 KB
testcase_27 AC 285 ms
109,016 KB
testcase_28 AC 285 ms
109,040 KB
testcase_29 AC 399 ms
158,976 KB
testcase_30 AC 395 ms
158,036 KB
testcase_31 AC 397 ms
158,060 KB
testcase_32 AC 393 ms
158,292 KB
testcase_33 AC 976 ms
137,548 KB
testcase_34 AC 999 ms
137,024 KB
testcase_35 AC 1,014 ms
137,824 KB
testcase_36 AC 969 ms
137,280 KB
testcase_37 AC 1,022 ms
137,324 KB
testcase_38 AC 996 ms
136,792 KB
testcase_39 AC 984 ms
136,960 KB
testcase_40 AC 357 ms
101,184 KB
testcase_41 AC 348 ms
96,872 KB
testcase_42 AC 639 ms
105,840 KB
testcase_43 AC 148 ms
84,312 KB
testcase_44 AC 847 ms
124,632 KB
testcase_45 AC 361 ms
100,820 KB
testcase_46 AC 560 ms
112,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

class Segtree():
    def __init__(self):
        self.tree = [-1 * 10 ** 9 for _ in range(1 << 19)]

    def set(self, n, k):
        n += (1 << 18)
        ret = -1 * (10 ** 9)
        
        now = n
        self.tree[now] = k
        while now > 1:
            now = now // 2
            self.tree[now] = max(self.tree[now * 2], self.tree[now * 2 + 1])

    def out(self, x):
        print(self.tree[(1 << 18) : (1 << 18) + x])        
    
    def get(self, n):
        return self.tree[n + (1 << 18)]
    
    def prod(self, l, r):
        l += (1 << 18)
        r += (1 << 18)
        if l >= r:
            return -1 * (10 ** 9)
        
        left_ret = -1 * (10 ** 9)
        right_ret = -1 * (10 ** 9)
        while l < r:
            if l % 2 == 1:
                left_ret = max(left_ret, self.tree[l])
                l += 1
            
            if r % 2 == 1:
                r -= 1
                right_ret = max(right_ret, self.tree[r])
            
            l = l // 2
            r = r // 2
        
        return max(left_ret, right_ret)

H, W, N, P = map(int, input().split())
sy = set()
sy.add(1)
plst = []
for i in range(N):
    x, y = map(int, input().split())
    sy.add(y)
    plst.append([x, y])

plst.sort()
#print(plst)

ly = list(sy)
ly.sort()

#print(ly)

d = defaultdict(int)
for i in range(len(ly)):
    d[ly[i]] = i

seg = Segtree()

seg.set(d[1], 0)

for i in range(N):
    vy = d[plst[i][1]]
    val = seg.get(vy)
    prd = seg.prod(0, vy + 1)
    seg.set(vy, max(prd, val) + 1)

max_omen = seg.prod(0, (1 << 18))

mod = 998244353

def inv(p):
    return pow(p, mod - 2, mod)

ans = 1

ans = (ans * pow(P - 1, H + W - 3 - max_omen, mod)) % mod
ans = (ans * pow(P - 2, max_omen, mod)) % mod

ans = (pow(P, H + W - 3, mod) - ans + mod) % mod

ans = (ans * inv(pow(P, H + W - 3, mod))) % mod
print(ans)
0