結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-01 21:16:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,420 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 170,224 KB
最終ジャッジ日時 2023-09-23 13:38:51
合計ジャッジ時間 11,810 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 74 ms
71,240 KB
testcase_02 AC 79 ms
71,228 KB
testcase_03 AC 75 ms
71,496 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 76 ms
71,396 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 910 ms
170,224 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 921 ms
169,976 KB
testcase_16 AC 933 ms
169,952 KB
testcase_17 AC 905 ms
170,016 KB
testcase_18 RE -
testcase_19 AC 975 ms
169,476 KB
testcase_20 AC 1,039 ms
169,692 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 77 ms
71,472 KB
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

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 points:
      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