結果

問題 No.1864 Shortest Paths Counting
ユーザー shobonvipshobonvip
提出日時 2022-03-04 23:02:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 1,995 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 137,004 KB
最終ジャッジ日時 2023-09-26 02:15:18
合計ジャッジ時間 7,623 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,440 KB
testcase_01 AC 68 ms
71,416 KB
testcase_02 AC 67 ms
71,304 KB
testcase_03 AC 68 ms
71,140 KB
testcase_04 AC 67 ms
71,116 KB
testcase_05 AC 68 ms
71,628 KB
testcase_06 AC 70 ms
71,164 KB
testcase_07 AC 70 ms
71,436 KB
testcase_08 AC 68 ms
71,344 KB
testcase_09 AC 245 ms
89,140 KB
testcase_10 AC 262 ms
89,884 KB
testcase_11 AC 238 ms
89,084 KB
testcase_12 AC 367 ms
106,384 KB
testcase_13 AC 240 ms
89,200 KB
testcase_14 AC 262 ms
90,400 KB
testcase_15 AC 296 ms
96,624 KB
testcase_16 AC 245 ms
89,164 KB
testcase_17 AC 288 ms
95,296 KB
testcase_18 AC 276 ms
92,376 KB
testcase_19 AC 242 ms
89,256 KB
testcase_20 AC 327 ms
99,588 KB
testcase_21 AC 227 ms
88,804 KB
testcase_22 AC 285 ms
92,432 KB
testcase_23 AC 249 ms
89,348 KB
testcase_24 AC 71 ms
71,388 KB
testcase_25 AC 573 ms
137,004 KB
testcase_26 AC 197 ms
88,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# DIST a-b = 2X, a+b = 2Y として定める.


mod = 998244353


class BIT:
	"""
	<Attention> 0-indexed.
	query ... return the sum [0 to m]
	sum ... return the sum [a to b]
	sumall ... return the sum [all]
	add ... 'add' number to element (be careful that it doesn't set a value.)
	search ... the sum version of bisect.right
	output ... return the n-th element
	listout ... return the BIT list
	"""
	
	def query(self, m):
		res = 0
		while m > 0:
			res = (res+self.bit[m])%mod
			m -= m&(-m)
		return res
	
	def sum(self, a, b):
		return (self.query(b)-self.query(a))%mod
	
	def sumall(self):
		bitlen = self.bitlen-1
		return self.query(bitlen)
	
	def add(self, m, x):
		m += 1
		bitlen = len(self.bit)
		while m <= bitlen-1:
			self.bit[m] = (self.bit[m]+x)%mod
			m += m&(-m)
		return
	
	def output(self, a):
		return self.query(a+1)-self.query(a)
	
	def listout(self):
		return self.bit
	
	def __init__(self, a):
		self.bitlen = a+1
		self.bit = [0]*(a+1)


n = int(input())

a = []
sx, sy = 0, 0
gx, gy = 0, 0

for i in range(n):
	x, y = map(int, input().split())
	if i == 0:
		sx, sy = x + y, x - y
	elif i == n-1:
		gx, gy = x + y, x - y
	else:
		a.append((x + y, x - y))

#print(sx, sy, gx, gy)

if gx <= sx:
	sx, sy, gx, gy = gx, gy, sx, sy

ymin = min(sy, gy)
ymax = max(sy, gy)

b = []
c = []



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


for i in range(n-2):
	if sx <= a[i][0] <= gx and ymin <= a[i][1] <= ymax:
		b.append((a[i][0], a[i][1]))
		c.append(a[i][1])

mode = 0

if sy <= gy:
	# increase
	mode = 1

c_cmp = compress(c)

# print(c)
# print(c_cmp)
#print(b)

# if

b.sort()

size = len(b)
dp = [0 for i in range(size+1)]
dp[0] = 1

bit = BIT(size+1)
ans = 0

if mode:
	bit.add(0, 1)
	for i in range(size):
		bit.add(c_cmp[b[i][1]]+1, bit.query(c_cmp[b[i][1]]+2))
	print(bit.sumall())
else:
	bit.add(size, 1)
	for i in range(size):
		bit.add(c_cmp[b[i][1]], bit.sum(c_cmp[b[i][1]], size+1))
	print(bit.sumall())
0