結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-01 21:20:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,363 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 72,280 KB
最終ジャッジ日時 2023-09-23 13:41:30
合計ジャッジ時間 30,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,412 KB
testcase_01 AC 16 ms
8,236 KB
testcase_02 AC 17 ms
8,344 KB
testcase_03 AC 17 ms
8,344 KB
testcase_04 AC 16 ms
8,348 KB
testcase_05 AC 16 ms
8,288 KB
testcase_06 AC 16 ms
8,300 KB
testcase_07 AC 16 ms
8,284 KB
testcase_08 AC 17 ms
8,348 KB
testcase_09 AC 1,405 ms
69,524 KB
testcase_10 AC 1,525 ms
69,332 KB
testcase_11 AC 1,521 ms
68,764 KB
testcase_12 AC 1,964 ms
72,280 KB
testcase_13 AC 1,540 ms
69,628 KB
testcase_14 AC 1,710 ms
71,968 KB
testcase_15 AC 1,500 ms
69,284 KB
testcase_16 AC 1,552 ms
70,124 KB
testcase_17 AC 1,466 ms
69,048 KB
testcase_18 AC 1,585 ms
69,912 KB
testcase_19 AC 1,688 ms
70,400 KB
testcase_20 TLE -
testcase_21 AC 1,794 ms
71,148 KB
testcase_22 AC 1,559 ms
70,216 KB
testcase_23 AC 1,433 ms
69,140 KB
testcase_24 AC 16 ms
8,244 KB
testcase_25 TLE -
testcase_26 AC 1,195 ms
67,712 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