結果
問題 | No.1864 Shortest Paths Counting |
ユーザー | Chippppp |
提出日時 | 2022-03-01 20:30:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,176 bytes |
コンパイル時間 | 306 ms |
コンパイル使用メモリ | 86,992 KB |
実行使用メモリ | 170,696 KB |
最終ジャッジ日時 | 2023-09-23 13:38:37 |
合計ジャッジ時間 | 18,279 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,192 KB |
testcase_01 | AC | 70 ms
71,216 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 70 ms
71,228 KB |
testcase_05 | WA | - |
testcase_06 | AC | 71 ms
71,104 KB |
testcase_07 | WA | - |
testcase_08 | AC | 70 ms
71,160 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 67 ms
71,180 KB |
testcase_25 | WA | - |
testcase_26 | AC | 835 ms
169,784 KB |
ソースコード
def main(): mod = 998244353 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 = [i for i, j in points] mem = compress(y) for i in range(N): points[i][1] = mem[y[i]] points[1:-1] = sorted(points[1:-1]) ft = FenwickTreeMod(len(mem)) ft.add(0, 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()