結果

問題 No.1864 Shortest Paths Counting
ユーザー 👑 tamatotamato
提出日時 2022-03-04 23:02:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 1,867 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 185,884 KB
最終ジャッジ日時 2023-09-26 02:15:46
合計ジャッジ時間 18,762 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,380 KB
testcase_01 AC 69 ms
71,480 KB
testcase_02 AC 68 ms
71,760 KB
testcase_03 AC 69 ms
71,648 KB
testcase_04 AC 69 ms
71,756 KB
testcase_05 AC 68 ms
71,560 KB
testcase_06 AC 66 ms
71,748 KB
testcase_07 AC 68 ms
71,444 KB
testcase_08 AC 67 ms
71,692 KB
testcase_09 AC 909 ms
174,904 KB
testcase_10 AC 963 ms
167,540 KB
testcase_11 AC 963 ms
173,632 KB
testcase_12 AC 1,069 ms
179,884 KB
testcase_13 AC 957 ms
167,524 KB
testcase_14 AC 1,018 ms
179,928 KB
testcase_15 AC 935 ms
173,560 KB
testcase_16 AC 902 ms
166,668 KB
testcase_17 AC 922 ms
173,452 KB
testcase_18 AC 1,003 ms
180,124 KB
testcase_19 AC 975 ms
172,864 KB
testcase_20 AC 1,044 ms
167,672 KB
testcase_21 AC 1,040 ms
179,516 KB
testcase_22 AC 958 ms
168,268 KB
testcase_23 AC 909 ms
167,752 KB
testcase_24 AC 68 ms
71,640 KB
testcase_25 AC 691 ms
166,116 KB
testcase_26 AC 627 ms
185,884 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]
                s %= mod
                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