結果
問題 | No.1898 Battle and Exchange |
ユーザー | polylogK |
提出日時 | 2021-12-27 00:54:33 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,111 ms / 5,000 ms |
コード長 | 1,652 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 54,784 KB |
最終ジャッジ日時 | 2024-10-05 11:21:40 |
合計ジャッジ時間 | 26,257 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
11,136 KB |
testcase_01 | AC | 28 ms
11,008 KB |
testcase_02 | AC | 28 ms
11,008 KB |
testcase_03 | AC | 27 ms
11,008 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 30 ms
11,136 KB |
testcase_06 | AC | 33 ms
11,008 KB |
testcase_07 | AC | 34 ms
11,008 KB |
testcase_08 | AC | 30 ms
11,008 KB |
testcase_09 | AC | 105 ms
13,184 KB |
testcase_10 | AC | 29 ms
11,136 KB |
testcase_11 | AC | 29 ms
11,008 KB |
testcase_12 | AC | 39 ms
11,008 KB |
testcase_13 | AC | 29 ms
11,008 KB |
testcase_14 | AC | 37 ms
11,008 KB |
testcase_15 | AC | 28 ms
11,136 KB |
testcase_16 | AC | 31 ms
11,008 KB |
testcase_17 | AC | 73 ms
13,056 KB |
testcase_18 | AC | 204 ms
19,840 KB |
testcase_19 | AC | 329 ms
24,448 KB |
testcase_20 | AC | 313 ms
25,600 KB |
testcase_21 | AC | 881 ms
47,232 KB |
testcase_22 | AC | 27 ms
11,008 KB |
testcase_23 | AC | 30 ms
11,008 KB |
testcase_24 | AC | 29 ms
11,008 KB |
testcase_25 | AC | 34 ms
11,008 KB |
testcase_26 | AC | 28 ms
11,008 KB |
testcase_27 | AC | 55 ms
11,264 KB |
testcase_28 | AC | 64 ms
11,520 KB |
testcase_29 | AC | 141 ms
12,032 KB |
testcase_30 | AC | 37 ms
11,008 KB |
testcase_31 | AC | 29 ms
11,008 KB |
testcase_32 | AC | 311 ms
23,936 KB |
testcase_33 | AC | 545 ms
33,792 KB |
testcase_34 | AC | 254 ms
21,888 KB |
testcase_35 | AC | 412 ms
28,160 KB |
testcase_36 | AC | 378 ms
26,368 KB |
testcase_37 | AC | 124 ms
16,128 KB |
testcase_38 | AC | 1,111 ms
54,784 KB |
testcase_39 | AC | 720 ms
45,568 KB |
testcase_40 | AC | 997 ms
50,048 KB |
testcase_41 | AC | 662 ms
43,008 KB |
testcase_42 | AC | 69 ms
12,544 KB |
testcase_43 | AC | 600 ms
38,144 KB |
testcase_44 | AC | 28 ms
11,008 KB |
testcase_45 | AC | 100 ms
14,208 KB |
testcase_46 | AC | 336 ms
24,192 KB |
testcase_47 | AC | 79 ms
13,056 KB |
testcase_48 | AC | 133 ms
15,744 KB |
testcase_49 | AC | 55 ms
11,392 KB |
testcase_50 | AC | 54 ms
11,264 KB |
testcase_51 | AC | 54 ms
11,392 KB |
testcase_52 | AC | 80 ms
11,520 KB |
testcase_53 | AC | 251 ms
18,176 KB |
testcase_54 | AC | 346 ms
18,560 KB |
testcase_55 | AC | 319 ms
19,712 KB |
testcase_56 | AC | 363 ms
21,504 KB |
testcase_57 | AC | 1,083 ms
51,072 KB |
testcase_58 | AC | 1,015 ms
50,944 KB |
testcase_59 | AC | 979 ms
50,944 KB |
testcase_60 | AC | 997 ms
51,200 KB |
ソースコード
import heapq def solve(n, m, graph, abc): for i in range(n): abc[i].sort(reverse=True) ans = sum(abc[0]) - 1 myabc = [ans, 1, 1] myabc[1] = abc[0][0] v = graph[0][0] for to in graph[0]: if sum(abc[to]) < sum(abc[v]): v = to if sum(abc[v]) >= sum(myabc): ans += sum(abc[v]) - sum(myabc) + 1 myabc = [ans, 1, 1] q, visit = [], [False] * n heapq.heappush(q, (sum(abc[0]), 0)) visit[0] = True while q: nowsum, now = heapq.heappop(q) if nowsum >= sum(myabc): diff = nowsum - sum(myabc) + 1 if myabc[0] == ans: ans += diff myabc[0] += diff elif myabc[1] == ans: ans += diff myabc[1] += diff elif myabc[2] == ans: ans += diff myabc[2] += diff else: ans = myabc[2] + diff myabc[2] += diff if now == n - 1: return ans, 1, 1 myabc += abc[now] myabc.sort(reverse=True) myabc = myabc[:3] for to in graph[now]: if visit[to]: continue visit[to] = True heapq.heappush(q, (sum(abc[to]), to)) if __name__ == '__main__': n, m = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 graph[u].append(v) graph[v].append(u) abc = [list(map(int, input().split())) for _ in range(n)] a, b, c = solve(n, m, graph, abc) print(a, b, c)