結果

問題 No.134 走れ!サブロー君
ユーザー しらっ亭しらっ亭
提出日時 2015-07-28 01:58:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,265 ms / 5,000 ms
コード長 1,209 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 38,204 KB
最終ジャッジ日時 2024-04-22 18:03:39
合計ジャッジ時間 3,759 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 27 ms
10,880 KB
testcase_03 AC 35 ms
11,008 KB
testcase_04 AC 52 ms
11,520 KB
testcase_05 AC 86 ms
12,416 KB
testcase_06 AC 198 ms
15,896 KB
testcase_07 AC 494 ms
23,208 KB
testcase_08 AC 1,265 ms
38,204 KB
testcase_09 AC 462 ms
21,612 KB
testcase_10 AC 27 ms
10,880 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 25 ms
10,880 KB
testcase_13 AC 26 ms
10,880 KB
testcase_14 AC 26 ms
10,624 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 i in range(N):
        x, y, w = list(input().split())
        X[i], Y[i], W[i] = int(x), int(y), float(w)

    memo = {}

    def mrec(v, w, c):
        """v: 配達済みの店の集合、w: 今積んでる量(cで下ろし済み)、c:今いる店 = c に移動するまでの時間"""
        if (v, w, c) in memo:
            return memo[v, w, c]

        if v == 0:
            ret = time(w + W[c], SX, SY, X[c], Y[c])
        else:
            mi = 9999999999999
            for i in range(N):
                i1 = 1 << i
                if v & i1 and i != c:
                    # i から来た可能性
                    mi = min(mi, time(w + W[c], X[i], Y[i], X[c], Y[c]) + mrec(v - i1, w + W[c], i))
            ret = mi

        memo[v, w, c] = ret
        return ret


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


def main():
    solve()


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