結果
問題 | No.1864 Shortest Paths Counting |
ユーザー | mkawa2 |
提出日時 | 2024-06-19 17:22:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 369 ms / 2,000 ms |
コード長 | 2,535 bytes |
コンパイル時間 | 312 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 132,196 KB |
最終ジャッジ日時 | 2024-06-19 17:23:06 |
合計ジャッジ時間 | 8,959 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,208 KB |
testcase_01 | AC | 41 ms
55,264 KB |
testcase_02 | AC | 41 ms
55,064 KB |
testcase_03 | AC | 41 ms
55,224 KB |
testcase_04 | AC | 40 ms
55,140 KB |
testcase_05 | AC | 40 ms
55,256 KB |
testcase_06 | AC | 41 ms
54,368 KB |
testcase_07 | AC | 40 ms
55,388 KB |
testcase_08 | AC | 40 ms
54,944 KB |
testcase_09 | AC | 256 ms
109,596 KB |
testcase_10 | AC | 241 ms
110,516 KB |
testcase_11 | AC | 228 ms
109,176 KB |
testcase_12 | AC | 369 ms
126,440 KB |
testcase_13 | AC | 235 ms
109,068 KB |
testcase_14 | AC | 250 ms
109,944 KB |
testcase_15 | AC | 271 ms
113,948 KB |
testcase_16 | AC | 236 ms
109,360 KB |
testcase_17 | AC | 279 ms
112,748 KB |
testcase_18 | AC | 258 ms
110,732 KB |
testcase_19 | AC | 233 ms
109,476 KB |
testcase_20 | AC | 283 ms
117,416 KB |
testcase_21 | AC | 243 ms
103,640 KB |
testcase_22 | AC | 256 ms
110,808 KB |
testcase_23 | AC | 248 ms
109,552 KB |
testcase_24 | AC | 41 ms
55,092 KB |
testcase_25 | AC | 357 ms
132,196 KB |
testcase_26 | AC | 217 ms
107,472 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from collections import defaultdict class BitSum: def __init__(self, n): self._n = n+1 self._table = [0]*self._n self._origin = [0]*n def __getitem__(self, item): return self._origin[item] def __setitem__(self, index, value): self.add(index, value-self._origin[index]) self._origin[index] = value def add(self, i, x): if x == 0: return self._origin[i] += x i += 1 while i < self._n: self._table[i] += x self._table[i] %= md i += i & -i def sum(self, r): res = 0 while r > 0: res += self._table[r] res %= md r -= r & -r return res def sumlr(self, l, r): if l >= r: return 0 if l == 0: return self.sum(r) return self.sum(r)-self.sum(l) # return "min(i) of sum(a[0]..a[i])>=x" or "N" def bisect(self, x): idx = 0 d = 1 << (self._n-1).bit_length()-1 while d: if idx | d < self._n and self._table[idx | d] < x: idx |= d x -= self._table[idx] d >>= 1 return idx n = II() xy = LLI(n) xy = [(x+y, x-y) for x, y in xy] sx, sy = xy[0] xy = [(x-sx, y-sy) for x, y in xy] gx, gy = xy[-1] c=d=1 if gx<0:c=-1 if gy<0:d=-1 xy=[(x*c,y*d) for x,y in xy][1:] gx, gy = xy[-1] dec = set() dec.add(0) x2y = defaultdict(list) for x, y in xy: if x < 0 or x > gx or y < 0 or y > gy: continue dec.add(y) x2y[x].append(y) enc = {a: i for i, a in enumerate(sorted(dec))} bit = BitSum(len(enc)+5) bit.add(0,1) s=0 for x in sorted(x2y): yy = x2y[x] yy.sort() for y in yy: y=enc[y] s=bit.sum(y+1) bit.add(y,s) print(s)