結果
問題 | No.1014 competitive fighting |
ユーザー | maspy |
提出日時 | 2020-03-21 01:59:07 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,830 ms / 2,000 ms |
コード長 | 1,984 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 144,296 KB |
最終ジャッジ日時 | 2024-07-07 12:58:12 |
合計ジャッジ時間 | 76,924 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
外部呼び出し有り |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,683 ms
56,284 KB |
testcase_01 | AC | 954 ms
56,544 KB |
testcase_02 | AC | 952 ms
56,668 KB |
testcase_03 | AC | 958 ms
56,408 KB |
testcase_04 | AC | 954 ms
56,532 KB |
testcase_05 | AC | 1,636 ms
95,556 KB |
testcase_06 | AC | 1,575 ms
95,880 KB |
testcase_07 | AC | 1,567 ms
95,592 KB |
testcase_08 | AC | 1,481 ms
92,316 KB |
testcase_09 | AC | 1,561 ms
95,672 KB |
testcase_10 | AC | 1,291 ms
85,396 KB |
testcase_11 | AC | 1,720 ms
123,540 KB |
testcase_12 | AC | 1,559 ms
95,640 KB |
testcase_13 | AC | 1,177 ms
72,456 KB |
testcase_14 | AC | 1,164 ms
70,532 KB |
testcase_15 | AC | 1,246 ms
75,076 KB |
testcase_16 | AC | 967 ms
57,040 KB |
testcase_17 | AC | 1,042 ms
59,868 KB |
testcase_18 | AC | 1,423 ms
88,064 KB |
testcase_19 | AC | 1,572 ms
94,936 KB |
testcase_20 | AC | 1,129 ms
67,112 KB |
testcase_21 | AC | 1,384 ms
84,540 KB |
testcase_22 | AC | 1,308 ms
78,480 KB |
testcase_23 | AC | 1,079 ms
62,108 KB |
testcase_24 | AC | 1,076 ms
62,472 KB |
testcase_25 | AC | 988 ms
57,944 KB |
testcase_26 | AC | 1,364 ms
84,952 KB |
testcase_27 | AC | 1,046 ms
59,848 KB |
testcase_28 | AC | 1,061 ms
60,552 KB |
testcase_29 | AC | 965 ms
57,052 KB |
testcase_30 | AC | 1,445 ms
91,152 KB |
testcase_31 | AC | 1,396 ms
86,000 KB |
testcase_32 | AC | 960 ms
56,792 KB |
testcase_33 | AC | 999 ms
58,840 KB |
testcase_34 | AC | 1,657 ms
106,456 KB |
testcase_35 | AC | 1,789 ms
118,484 KB |
testcase_36 | AC | 1,560 ms
102,972 KB |
testcase_37 | AC | 978 ms
57,820 KB |
testcase_38 | AC | 1,473 ms
96,448 KB |
testcase_39 | AC | 1,219 ms
73,028 KB |
testcase_40 | AC | 1,503 ms
97,124 KB |
testcase_41 | AC | 1,324 ms
84,704 KB |
testcase_42 | AC | 1,830 ms
121,720 KB |
testcase_43 | AC | 992 ms
57,820 KB |
testcase_44 | AC | 1,755 ms
115,068 KB |
testcase_45 | AC | 1,379 ms
86,952 KB |
testcase_46 | AC | 1,060 ms
60,284 KB |
testcase_47 | AC | 1,193 ms
72,696 KB |
testcase_48 | AC | 1,523 ms
100,408 KB |
testcase_49 | AC | 982 ms
56,636 KB |
testcase_50 | AC | 1,803 ms
118,196 KB |
testcase_51 | AC | 1,428 ms
92,836 KB |
testcase_52 | AC | 984 ms
57,032 KB |
testcase_53 | AC | 1,551 ms
144,296 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import connected_components N = int(readline()) ABC = np.array(read().split(), np.int64) A = ABC[::3] B = ABC[1::3] C = ABC[2::3] sort_key = (A << 32) + (B - C) ind = np.concatenate([np.argsort(sort_key), [N]]) nums = np.concatenate([[-10**10], A]) nums.sort() fr = [] to = [] cost = [] fr.append(ind[0:-2]) to.append(ind[1:-1]) fr.append([N]) to.append([ind[0]]) cost.append(np.zeros(N, np.int64)) fr.append(ind[np.searchsorted(nums, B - C, side='right') - 2]) to.append(np.arange(N)) cost.append(B) fr = np.concatenate(fr) to = np.concatenate(to) cost = np.concatenate(cost) G = csr_matrix((np.ones_like(fr), (fr, to)), (N + 1, N + 1)) n_comp, comp = connected_components(G, directed=True, connection='strong') comp = comp.tolist() INF = 10 ** 18 fr = fr.tolist() to = to.tolist() cost = cost.tolist() dp = [0] * (n_comp) G = [[] for _ in range(n_comp)] self_loop = [0] * n_comp in_deg = [0] * n_comp for v, w, c in zip(fr, to, cost): cv = comp[v] cw = comp[w] if cv == cw: if c == 0: continue if self_loop[cv]: self_loop[cv] = INF else: self_loop[cv] = c else: G[cv].append((cw, c)) in_deg[cw] += 1 deg_0 = [i for i, x in enumerate(in_deg) if not x] dp = [0] * (n_comp) while deg_0: v = deg_0.pop() dp[v] += self_loop[v] for w, c in G[v]: x = dp[v] + c if dp[w] < x: dp[w] = x in_deg[w] -= 1 if not in_deg[w]: deg_0.append(w) answer = [None] * N for v, w, c in zip(fr, to, cost): cv = comp[v] cw = comp[w] if c == 0: continue if cv == cw: x = dp[cv] else: x = dp[cv] + c answer[w] = str(x) if x < INF else 'BAN' print('\n'.join(map(str, answer)))