結果

問題 No.1864 Shortest Paths Counting
ユーザー tamatotamato
提出日時 2022-03-04 22:55:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,842 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,604 KB
実行使用メモリ 185,956 KB
最終ジャッジ日時 2023-09-26 02:08:40
合計ジャッジ時間 19,169 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,960 KB
testcase_01 AC 67 ms
71,524 KB
testcase_02 AC 68 ms
71,600 KB
testcase_03 AC 68 ms
72,000 KB
testcase_04 AC 68 ms
71,828 KB
testcase_05 AC 69 ms
71,464 KB
testcase_06 AC 69 ms
71,992 KB
testcase_07 AC 69 ms
71,816 KB
testcase_08 AC 69 ms
71,748 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 69 ms
71,936 KB
testcase_25 WA -
testcase_26 AC 647 ms
185,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                self.tree[i] %= mod
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

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

    if XY[0][0] > XY[-1][0]:
        XY = [(-x, y) for x, y in XY]
    if XY[0][1] > XY[-1][1]:
        XY = [(x, -y) for x, y in XY]
    XYI = []
    Y = set()
    for i, xy in enumerate(XY):
        x, y = xy
        XYI.append((x, y, i))
        Y.add(y)
    XYI.sort(key=lambda z: z[1])
    XYI.sort(key=lambda z: z[0])
    idx = {y: i + 1 for i, y in enumerate(sorted(list(Y)))}
    L = len(idx)
    bit = Bit(L)

    flg = 1
    for x, y, i in XYI:
        if flg:
            if i != 0:
                continue
            else:
                flg = 0
                bit.add(idx[y], 1)
                continue
        j = idx[y]
        a = bit.sum(j)
        if i == N - 1:
            print(a)
            break
        bit.add(j, a)


if __name__ == '__main__':
    main()
0