結果
問題 | No.1864 Shortest Paths Counting |
ユーザー |
|
提出日時 | 2022-03-01 20:25:56 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,120 bytes |
コンパイル時間 | 1,439 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 169,512 KB |
最終ジャッジ日時 | 2024-07-16 13:12:29 |
合計ジャッジ時間 | 17,197 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 3 |
other | AC * 1 RE * 22 |
ソースコード
def main():mod = 998244353class FenwickTreeMod:def __init__(self, n):self.n = nself.data = [0] * (n + 1)def add(self, k, x):k += 1while k <= self.n:self.data[k] += xself.data[k] %= modk += k & -kdef sum(self, k):res = 0while k:res += self.data[k]res %= modk -= k & -kreturn resdef compress(a):mem = {}for idx, elm in enumerate(sorted(set(a))):mem[elm] = idxreturn memN = int(input())points = [None] * Nfor i in range(N):a, b = map(int, input().split())points[i] = [a + b, a - b]if points[0][0] > points[-1][0]:for i in range(N):points[i][0] *= -1if points[0][1] > points[-1][1]:for i in range(N):points[i][1] *= -1y = [i for i, j in points]mem = compress(y)for i in range(N):points[i][0] = mem[y[i]]points[1:-1] = sorted(points[1:-1])ft = FenwickTreeMod(len(mem))ft.add(0, 1)for i in range(1, N - 1):ft.add(points[i][1], ft.sum(points[i][1] + 1))print(ft.sum(points[-1][1] + 1))main()