結果

問題 No.134 走れ!サブロー君
ユーザー しらっ亭しらっ亭
提出日時 2015-07-28 02:44:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 379 ms / 5,000 ms
コード長 1,248 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-04-22 18:03:42
合計ジャッジ時間 2,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 38 ms
11,008 KB
testcase_05 AC 54 ms
11,136 KB
testcase_06 AC 92 ms
11,520 KB
testcase_07 AC 185 ms
12,288 KB
testcase_08 AC 379 ms
14,464 KB
testcase_09 AC 347 ms
14,336 KB
testcase_10 AC 26 ms
10,752 KB
testcase_11 AC 26 ms
10,880 KB
testcase_12 AC 26 ms
10,752 KB
testcase_13 AC 25 ms
10,752 KB
testcase_14 AC 26 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def time(w, x1, y1, x2, y2):
    tt = (w + 100) / 120 * (abs(x1 - x2) + abs(y1 - y2))
    return tt


def solve():
    SX, SY = list(map(int, input().split()))
    N = int(input())
    X = [0] * N
    Y = [0] * N
    W = [0] * N

    for v in range(N):
        x, y, w = list(input().split())
        X[v], Y[v], W[v] = int(x), int(y), float(w)

    dp = [[9999999999 for c in range(N)] for v in range(1 << N)]
    # v: 配達済みの店の集合(c含む)、c:今いる店 = c に移動するまでの時間

    WW = [0] * (1 << N)
    for v in range(1 << N):
        WW[v] = sum(W[c] for c in range(N) if (1 << c) & v == 0)

    for c in range(N):
        dp[1 << c][c] = time(WW[0], SX, SY, X[c], Y[c])

    for v in range(1 << N):
        for c in range(N):
            c1 = 1 << c
            if v & c1 == 0:
                continue
            for n in range(N):
                if c == n:
                    continue
                n1 = 1 << n
                if v & n1 == 0:
                    dp[v|n1][n] = min(dp[v|n1][n], dp[v][c] + time(WW[v], X[c], Y[c], X[n], Y[n]))

    mi = min(time(0, X[c], Y[c], SX, SY) + dp[-1][c] for c in range(N))
    print(mi + sum(W))


def main():
    solve()


if __name__ == '__main__':
    main()
0