結果
| 問題 | 
                            No.1864 Shortest Paths Counting
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-03-01 21:20:57 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,363 bytes | 
| コンパイル時間 | 424 ms | 
| コンパイル使用メモリ | 12,928 KB | 
| 実行使用メモリ | 75,188 KB | 
| 最終ジャッジ日時 | 2024-07-16 13:18:42 | 
| 合計ジャッジ時間 | 30,466 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 20 TLE * 3 | 
ソースコード
def main():
  mod = 998244353
  # mod 998244353のFenwickTree
  class FenwickTreeMod:
    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
        k -= k & -k
      return res
  # 座標圧縮
  def compress(a):
    mem = {}
    for idx, elm in enumerate(sorted(set(a))):
      mem[elm] = idx
    return mem
  # 入力
  N = int(input())
  points = [None] * N
  for 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] *= -1
  if points[0][1] > points[-1][1]:
    for i in range(N):
      points[i][1] *= -1
  
  # y座標を圧縮
  y = [j for i, j in points]
  mem = compress(y)
  for i in range(N):
    points[i][1] = mem[y[i]]
  
  # 点1, N - 1以外をソート
  points[1:-1] = sorted(points[1:-1])
  # DP
  ft = FenwickTreeMod(len(mem))
  ft.add(points[0][1], 1)
  for i in range(1, N - 1):
    if points[0][0] <= points[i][0] <= points[-1][0]:
      ft.add(points[i][1], ft.sum(points[i][1] + 1))
  # 出力
  print(ft.sum(points[-1][1] + 1))
main()