結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-01 21:20:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,201 ms / 2,000 ms
コード長 1,363 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 170,468 KB
最終ジャッジ日時 2023-09-23 13:40:27
合計ジャッジ時間 20,579 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,228 KB
testcase_01 AC 73 ms
71,164 KB
testcase_02 AC 71 ms
71,244 KB
testcase_03 AC 72 ms
71,240 KB
testcase_04 AC 72 ms
71,308 KB
testcase_05 AC 72 ms
71,244 KB
testcase_06 AC 73 ms
71,164 KB
testcase_07 AC 74 ms
71,136 KB
testcase_08 AC 74 ms
71,100 KB
testcase_09 AC 982 ms
169,860 KB
testcase_10 AC 1,024 ms
169,620 KB
testcase_11 AC 1,015 ms
170,468 KB
testcase_12 AC 1,106 ms
169,804 KB
testcase_13 AC 1,023 ms
169,724 KB
testcase_14 AC 1,054 ms
169,760 KB
testcase_15 AC 1,019 ms
170,200 KB
testcase_16 AC 1,030 ms
169,996 KB
testcase_17 AC 1,024 ms
169,868 KB
testcase_18 AC 1,044 ms
170,264 KB
testcase_19 AC 1,062 ms
169,772 KB
testcase_20 AC 1,139 ms
169,632 KB
testcase_21 AC 1,075 ms
169,616 KB
testcase_22 AC 1,000 ms
169,984 KB
testcase_23 AC 981 ms
170,028 KB
testcase_24 AC 71 ms
71,044 KB
testcase_25 AC 1,201 ms
170,036 KB
testcase_26 AC 902 ms
169,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0