結果

問題 No.1864 Shortest Paths Counting
ユーザー shiomusubi496shiomusubi496
提出日時 2022-01-05 16:44:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 17,436 KB
最終ジャッジ日時 2023-09-23 13:35:22
合計ジャッジ時間 7,772 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import itertools

mod = 998244353

class BinaryIndexedTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
    def add(self, k, x):
        k += 1
        while k <= self.n:
            self.data[k] += x
            self.data[k] %= mod
            k += k & -k
    def sum(self, k):
        res = 0
        while k:
            res += self.data[k]
            res %= mod
        return res

def compress(A):
    B = [l[0] for l in itertools.groupby(sorted(A))]
    A = [bisect.bisect_left(B, i) for i in A]
    return len(B)

N = int(input())
X = []
Y = []
for i in range(N):
    a, b = map(int, input().split())
    X += [a + b]
    Y += [a - b]
if X[0] > X[-1]:
    for i in range(N):
        X[i] = -X[i]
if Y[0] > Y[-1]:
    for i in range(N):
        Y[i] = -Y[i]

compress(X)
K = compress(Y)
A = []
for i in range(N):
    if X[0] > X[i] or X[i] > X[-1]:
        continue
    if Y[0] > Y[i] or Y[i] > Y[-1]:
        continue
    A += [(X[i], Y[i])]
M = len(A)
A.sort()
BIT = BinaryIndexedTree(K)
for i in range(M):
    if i == 0:
        BIT.add(0, 1)
    elif i == M - 1:
        print(BIT.sum(K))
    else:
        BIT.add(A[i][1], BIT.sum(A[i][1] + 1))
0