結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-01 22:00:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,386 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 79,556 KB
最終ジャッジ日時 2023-09-23 13:43:53
合計ジャッジ時間 27,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
29,532 KB
testcase_01 AC 120 ms
29,736 KB
testcase_02 AC 122 ms
29,668 KB
testcase_03 AC 125 ms
29,688 KB
testcase_04 AC 124 ms
29,672 KB
testcase_05 AC 126 ms
29,708 KB
testcase_06 AC 124 ms
29,752 KB
testcase_07 AC 122 ms
29,720 KB
testcase_08 AC 125 ms
29,760 KB
testcase_09 AC 1,103 ms
67,660 KB
testcase_10 AC 1,170 ms
68,296 KB
testcase_11 AC 1,048 ms
67,364 KB
testcase_12 AC 1,568 ms
72,300 KB
testcase_13 AC 1,046 ms
67,352 KB
testcase_14 AC 1,217 ms
68,568 KB
testcase_15 AC 1,284 ms
70,240 KB
testcase_16 AC 1,156 ms
67,796 KB
testcase_17 AC 1,237 ms
69,840 KB
testcase_18 AC 1,249 ms
69,280 KB
testcase_19 AC 1,113 ms
67,936 KB
testcase_20 AC 1,379 ms
70,548 KB
testcase_21 AC 1,107 ms
67,076 KB
testcase_22 AC 1,178 ms
69,084 KB
testcase_23 AC 1,127 ms
67,840 KB
testcase_24 AC 130 ms
29,520 KB
testcase_25 TLE -
testcase_26 AC 912 ms
67,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  import numpy as np

  mod = 998244353

  # mod 998244353のFenwickTree
  class FenwickTreeMod:
    def __init__(self, n):
      self.n = n
      self.data = np.zeros(n + 1, dtype = np.int64)
    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())
  X, Y = np.zeros(N, dtype = np.int64), np.zeros(N, dtype = np.int64)
  for i in range(N):
    a, b = map(int, input().split())
    X[i], Y[i] = a + b, a - b

  # 座標を反転しておく
  if X[0] > X[-1]:
    for i in range(N):
      X[i] = -X[i]
  if Y[0] > Y[-1]:
    for i in range(N):
      Y[i] = -Y[i]
  
  # y座標を圧縮
  mem = compress(Y)
  for i in range(N):
    Y[i] = mem[Y[i]]
  
  # x, y座標が範囲内の点のみソート
  points = [(i, j) for i, j in zip(X, Y) if X[0] <= i <= X[-1] and Y[0] <= j <= Y[-1]]
  points.sort()

  # DP
  ft = FenwickTreeMod(len(mem))
  ft.add(Y[0], 1)
  for i in range(1, len(points) - 1):
    ft.add(points[i][1], ft.sum(points[i][1] + 1))

  # 出力
  print(ft.sum(Y[-1] + 1))
main()
0