結果

問題 No.845 最長の切符
ユーザー convexineqconvexineq
提出日時 2019-06-28 23:08:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 308 ms / 3,000 ms
コード長 1,197 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 86,124 KB
最終ジャッジ日時 2023-09-14 22:37:05
合計ジャッジ時間 5,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,388 KB
testcase_01 AC 75 ms
75,148 KB
testcase_02 AC 85 ms
76,388 KB
testcase_03 AC 76 ms
71,408 KB
testcase_04 AC 73 ms
71,352 KB
testcase_05 AC 74 ms
71,300 KB
testcase_06 AC 74 ms
71,140 KB
testcase_07 AC 76 ms
71,360 KB
testcase_08 AC 94 ms
76,696 KB
testcase_09 AC 78 ms
76,036 KB
testcase_10 AC 99 ms
77,048 KB
testcase_11 AC 91 ms
76,884 KB
testcase_12 AC 99 ms
76,588 KB
testcase_13 AC 91 ms
76,560 KB
testcase_14 AC 90 ms
76,696 KB
testcase_15 AC 140 ms
79,424 KB
testcase_16 AC 308 ms
86,124 KB
testcase_17 AC 150 ms
79,804 KB
testcase_18 AC 190 ms
81,240 KB
testcase_19 AC 114 ms
77,996 KB
testcase_20 AC 297 ms
85,624 KB
testcase_21 AC 288 ms
85,728 KB
testcase_22 AC 148 ms
79,756 KB
testcase_23 AC 111 ms
77,564 KB
testcase_24 AC 304 ms
85,824 KB
testcase_25 AC 75 ms
71,104 KB
testcase_26 AC 111 ms
85,224 KB
testcase_27 AC 75 ms
71,284 KB
testcase_28 AC 119 ms
84,888 KB
testcase_29 AC 73 ms
71,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!


n,m = [int(i) for i in input().split()]
lrp = [[int(i) for i in input().split()] for _ in range(m)]
g = [[1e9]*n for _ in range(n)]
for l,r,p in lrp:
    if g[l-1][r-1] == 1e9: g[l-1][r-1] = p
    else: g[l-1][r-1] = max(g[l-1][r-1],p)
    if g[r-1][l-1] == 1e9: g[r-1][l-1] = p
    else: g[r-1][l-1] = max(g[r-1][l-1],p)


def generator_comb(n,k):
    _ALL=1<<n
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

# 下4桁;最後の位置
L = 1<<(n+4)
dp = [-1]*L

for i in range(n):
    dp[(1 << (i+4)) ^ i] = 0

for k in range(1,n):
    for i in generator_comb(n,k):
        for now in range(n):
            if i & (1 << now) == 0: continue
            ii = (i << 4)^now
            if dp[ii] < 0: continue
            for j in range(n):
                if i&(1 << j) != 0: continue
                if g[j][now] == 1e9: continue
                num = ((i^(1 << j))<<4)|j
                dp[num] = max(dp[num], dp[ii] + g[j][now])
    
#print([(str(bin(i>>4))[2:],i&15,d)  for i,d in enumerate(dp) if d > 0 ])
print(max(dp))





0