結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-01 21:18:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 930 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 86,592 KB
実行使用メモリ 169,972 KB
最終ジャッジ日時 2023-09-23 13:40:05
合計ジャッジ時間 17,258 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,252 KB
testcase_01 AC 61 ms
71,236 KB
testcase_02 AC 64 ms
71,012 KB
testcase_03 AC 62 ms
71,008 KB
testcase_04 AC 63 ms
71,016 KB
testcase_05 AC 63 ms
71,088 KB
testcase_06 AC 63 ms
71,232 KB
testcase_07 AC 62 ms
71,260 KB
testcase_08 AC 60 ms
71,196 KB
testcase_09 AC 722 ms
169,448 KB
testcase_10 AC 872 ms
169,424 KB
testcase_11 AC 771 ms
169,564 KB
testcase_12 AC 855 ms
169,468 KB
testcase_13 AC 768 ms
169,696 KB
testcase_14 AC 789 ms
169,816 KB
testcase_15 AC 774 ms
169,624 KB
testcase_16 AC 778 ms
169,652 KB
testcase_17 AC 753 ms
169,452 KB
testcase_18 AC 763 ms
169,724 KB
testcase_19 AC 789 ms
169,444 KB
testcase_20 AC 848 ms
169,432 KB
testcase_21 AC 801 ms
169,088 KB
testcase_22 AC 749 ms
169,312 KB
testcase_23 AC 715 ms
169,972 KB
testcase_24 AC 59 ms
71,000 KB
testcase_25 AC 930 ms
169,572 KB
testcase_26 AC 790 ms
169,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  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(readline())
  points = [None] * N
  for i in range(N):
    a, b = map(int, readline().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()
0