結果

問題 No.134 走れ!サブロー君
ユーザー tcltktcltk
提出日時 2021-05-18 05:18:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 409 ms / 5,000 ms
コード長 1,707 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 96,440 KB
最終ジャッジ日時 2024-04-16 19:33:50
合計ジャッジ時間 4,230 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
86,956 KB
testcase_01 AC 132 ms
87,300 KB
testcase_02 AC 127 ms
86,740 KB
testcase_03 AC 204 ms
90,044 KB
testcase_04 AC 223 ms
91,088 KB
testcase_05 AC 290 ms
91,572 KB
testcase_06 AC 297 ms
91,976 KB
testcase_07 AC 296 ms
93,004 KB
testcase_08 AC 409 ms
96,440 KB
testcase_09 AC 397 ms
95,804 KB
testcase_10 AC 124 ms
86,888 KB
testcase_11 AC 132 ms
86,824 KB
testcase_12 AC 129 ms
86,836 KB
testcase_13 AC 128 ms
86,888 KB
testcase_14 AC 126 ms
86,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """0 0
# 3
# 100 178 100
# 23 25 40
# 34 31 90
# """
# sys.stdin = io.StringIO(_INPUT)


def main():

    x0, y0 = map(int, input().split())
    Point = []
    Point.append((x0, y0, 0.0))
    N = int(input())
    for _ in range(N):
        x, y, w = input().split()
        Point.append((int(x), int(y), float(w)))
    N += 1

    total_weight = sum(Point[i][2] for i in range(N))

    dp = [[10**10] * N for _ in range(1<<N)]
    dp[1][0] = 0
    for s in range(1, 1<<N):
        weight = total_weight - sum(Point[i][2] for i in range(N) if s & (1<<i))
        move_time = (weight+100)/120
        for next_point in range(N):
            if s & (1<<next_point):
                continue
            for last_point in range(N):
                if s & (1<<last_point) == 0:
                    continue
                dist = abs(Point[next_point][0] - Point[last_point][0]) + abs(Point[next_point][1] - Point[last_point][1])
                t1 = dp[s][last_point] + dist * move_time + Point[next_point][2]
                s1 = s | (1<<next_point)
                dp[s1][next_point] = min(dp[s1][next_point], t1)

    min_time = 10**10
    for last_point in range(1, N):
        dist = abs(Point[last_point][0] - Point[0][0]) + abs(Point[last_point][1] - Point[0][1])
        time = dp[(1<<N)-1][last_point] + dist * (100/120)
        min_time = min(min_time, time)
    print(min_time)

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