結果

問題 No.2230 Good Omen of White Lotus
ユーザー shobonvipshobonvip
提出日時 2023-02-24 22:32:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 818 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 182,200 KB
最終ジャッジ日時 2023-10-11 06:33:24
合計ジャッジ時間 17,516 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,132 KB
testcase_01 AC 75 ms
71,268 KB
testcase_02 AC 72 ms
71,448 KB
testcase_03 AC 72 ms
71,120 KB
testcase_04 AC 73 ms
71,264 KB
testcase_05 AC 74 ms
71,120 KB
testcase_06 AC 73 ms
71,456 KB
testcase_07 AC 77 ms
71,596 KB
testcase_08 AC 73 ms
71,424 KB
testcase_09 AC 73 ms
71,412 KB
testcase_10 AC 76 ms
71,452 KB
testcase_11 AC 75 ms
71,516 KB
testcase_12 AC 76 ms
71,548 KB
testcase_13 AC 79 ms
71,420 KB
testcase_14 AC 257 ms
82,720 KB
testcase_15 AC 94 ms
76,180 KB
testcase_16 AC 329 ms
86,536 KB
testcase_17 AC 332 ms
86,496 KB
testcase_18 AC 330 ms
86,640 KB
testcase_19 AC 330 ms
86,568 KB
testcase_20 AC 150 ms
78,452 KB
testcase_21 AC 131 ms
77,884 KB
testcase_22 AC 149 ms
78,480 KB
testcase_23 AC 153 ms
78,284 KB
testcase_24 AC 85 ms
77,820 KB
testcase_25 AC 86 ms
77,524 KB
testcase_26 AC 87 ms
78,020 KB
testcase_27 AC 339 ms
107,164 KB
testcase_28 AC 337 ms
106,820 KB
testcase_29 AC 466 ms
174,128 KB
testcase_30 AC 469 ms
139,712 KB
testcase_31 AC 486 ms
182,200 KB
testcase_32 AC 496 ms
182,184 KB
testcase_33 AC 785 ms
146,268 KB
testcase_34 AC 772 ms
146,224 KB
testcase_35 AC 762 ms
146,348 KB
testcase_36 AC 814 ms
146,648 KB
testcase_37 AC 818 ms
145,904 KB
testcase_38 AC 780 ms
146,276 KB
testcase_39 AC 774 ms
145,888 KB
testcase_40 AC 387 ms
99,988 KB
testcase_41 AC 352 ms
95,568 KB
testcase_42 AC 527 ms
106,756 KB
testcase_43 AC 183 ms
80,780 KB
testcase_44 AC 697 ms
128,864 KB
testcase_45 AC 327 ms
98,804 KB
testcase_46 AC 503 ms
119,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
	def __init__(self, n):
		tmp = 0
		while n != 0:
			n >>= 1
			tmp += 1
		self.seglen = 1 << tmp
		self.inf = 0
		self.seg = [self.inf]*(self.seglen*2)
	
	def update(self, x, val):
		# update x to val;
		x += self.seglen
		self.seg[x] = val
		while x > 1:
			x >>= 1
			self.seg[x] = max(self.seg[2*x], self.seg[2*x+1])
	
	def allupdate(self, a):
		targ = self.seglen
		for i in range(len(a)):
			self.seg[targ + i] = a[i]
		for i in range(self.seglen-1, -1, -1):
			self.seg[i] = max(self.seg[2*i], self.seg[2*i+1])

	def query(self, l, r):
		l = max(l, 0) + self.seglen
		r = max(r, 0) + self.seglen
		lres, rres = self.inf, self.inf
		while l < r:
			if l & 1:
				lres = max(lres, self.seg[l])
				l += 1
			if r & 1:
				r -= 1
				rres = max(rres, self.seg[r])
			l >>= 1
			r >>= 1
		return max(lres, rres)

def compress(arr):
	*XS, = set(arr)
	XS.sort()
	return {cmp_e: cmp_i for cmp_i, cmp_e in enumerate(XS)}

h,w,n,p = map(int,input().split())
ys = []
bucket = [[] for i in range(h)]
for i in range(n):
	x, y = map(int,input().split())
	bucket[x-1].append(y-1)
	ys.append(y-1)
y_c = compress(ys)
m = len(y_c)

seg = SegmentTree(m)
for i in range(h):
	bucket[i].sort()
	for j in bucket[i]:
		targ = y_c[j]
		ast = seg.query(0, targ+1) + 1
		ar = seg.query(targ, targ + 1)
		seg.update(targ, max(ar, ast))

tmp = seg.query(0, m)

mod = 998244353
yes = (1 - 2 * pow(p, mod-2, mod)) % mod
no = (1 - pow(p, mod-2, mod)) % mod

def best_fraction(n:int, mod:int, strmode=0) -> tuple:
	w = 9 * 10 ** 18
	t = pow(n, mod-2, mod)
	ansx, ansy = 0, 0
	for b in range(1, mod):
		if b*b > w: break
		a = n*b % mod
		c = t*b % mod
		if a*b < w:
			w = a*b
			ansx, ansy = a, b
		if c*b < w:
			w = c*b
			ansx, ansy = b, c
	if strmode:
		return f"{n} = {ansx}/{ansy} (mod {mod})"
	return (ansx, ansy)


ans = (1 - pow(yes, tmp, mod) * pow(no, h+w-3-tmp, mod)) % mod
print(ans)
#print(best_fraction(ans, mod, 1))
0