結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー | ArcAki |
提出日時 | 2024-11-09 02:59:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,604 ms / 2,000 ms |
コード長 | 1,820 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 121,216 KB |
最終ジャッジ日時 | 2024-11-09 02:59:52 |
合計ジャッジ時間 | 25,485 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
61,952 KB |
testcase_01 | AC | 60 ms
62,208 KB |
testcase_02 | AC | 70 ms
66,304 KB |
testcase_03 | AC | 78 ms
69,376 KB |
testcase_04 | AC | 90 ms
72,960 KB |
testcase_05 | AC | 61 ms
62,592 KB |
testcase_06 | AC | 69 ms
66,176 KB |
testcase_07 | AC | 62 ms
62,336 KB |
testcase_08 | AC | 274 ms
97,024 KB |
testcase_09 | AC | 275 ms
97,280 KB |
testcase_10 | AC | 450 ms
99,328 KB |
testcase_11 | AC | 550 ms
101,120 KB |
testcase_12 | AC | 656 ms
103,296 KB |
testcase_13 | AC | 813 ms
104,576 KB |
testcase_14 | AC | 864 ms
107,008 KB |
testcase_15 | AC | 959 ms
108,416 KB |
testcase_16 | AC | 1,079 ms
110,336 KB |
testcase_17 | AC | 1,150 ms
111,744 KB |
testcase_18 | AC | 1,252 ms
113,664 KB |
testcase_19 | AC | 1,331 ms
115,968 KB |
testcase_20 | AC | 1,416 ms
117,504 KB |
testcase_21 | AC | 1,527 ms
118,912 KB |
testcase_22 | AC | 1,604 ms
121,088 KB |
testcase_23 | AC | 1,576 ms
121,216 KB |
testcase_24 | AC | 1,583 ms
121,216 KB |
testcase_25 | AC | 648 ms
103,040 KB |
testcase_26 | AC | 553 ms
100,992 KB |
testcase_27 | AC | 433 ms
99,200 KB |
testcase_28 | AC | 1,251 ms
113,920 KB |
testcase_29 | AC | 1,334 ms
115,712 KB |
testcase_30 | AC | 1,573 ms
121,216 KB |
ソースコード
from sys import stdin from random import randint from collections import deque, defaultdict as dd from copy import deepcopy input = stdin.readline MOD = 998244353 INF = 1 << 60 xor = randint(100, INF) def extended_gcd(a, b): if b == 0: return a, 1, 0 else: g, x, y = extended_gcd(b, a % b) return g, y, x - (a // b) * y def mod_inverse(a, m): _, x, _ = extended_gcd(a, m) return (x % m + m) % m def fast_mod_pow(x, p): res = 1 t = x z = p while z > 0: if z % 2 == 1: res = (res * t) t = (t * t) z //= 2 return res def main(): n, k = map(int, input().split()) p = [tuple(map(float, input().split()))for _ in range(n)] dist = [[0.for _ in range(n)]for _ in range(n)] for i in range(n): for j in range(n): x1, y1 = p[i] x2, y2 = p[j] dist[i][j] = ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5 central = [0.]*n for i in range(n): x, y = p[i] central[i] = (x*x+y*y)**0.5 dp = [[[1e60for _ in range(k)] for _ in range(n)]for _ in range(1<<n)] for i in range(n): dp[1<<i][i][0] = central[i] for bit in range(1<<n): for i in range(n): for j in range(k): for nex in range(n): shift = 1<<nex if bit & shift: continue nf = bit | shift dp[nf][nex][0] = min(dp[nf][nex][0], dp[bit][i][j]+central[i]+central[nex]) if j < k-1: dp[nf][nex][j+1] = min(dp[nf][nex][j+1], dp[bit][i][j]+dist[i][nex]) ans = 1e60 for i in range(n): for j in range(k): ans = min(ans, dp[(1<<n)-1][i][j]+central[i]) print(ans) if __name__ == "__main__": main()