結果

問題 No.357 品物の並び替え (Middle)
ユーザー mkawa2mkawa2
提出日時 2020-03-19 00:53:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 295 ms / 5,000 ms
コード長 975 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 9,280 KB
最終ジャッジ日時 2023-08-20 20:31:32
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
8,624 KB
testcase_01 AC 20 ms
8,764 KB
testcase_02 AC 22 ms
8,592 KB
testcase_03 AC 22 ms
8,652 KB
testcase_04 AC 22 ms
8,668 KB
testcase_05 AC 22 ms
8,736 KB
testcase_06 AC 20 ms
8,752 KB
testcase_07 AC 20 ms
8,732 KB
testcase_08 AC 24 ms
8,752 KB
testcase_09 AC 140 ms
8,900 KB
testcase_10 AC 44 ms
8,684 KB
testcase_11 AC 43 ms
8,812 KB
testcase_12 AC 295 ms
9,280 KB
testcase_13 AC 141 ms
8,956 KB
testcase_14 AC 140 ms
8,912 KB
testcase_15 AC 43 ms
8,784 KB
testcase_16 AC 74 ms
8,792 KB
testcase_17 AC 44 ms
8,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,m=MI()
    ss=[[0]*n for _ in range(n)]
    for _ in range(m):
        i1,i2,s=MI()
        ss[i1][i2]=s
    dp=[0]*(1<<n)
    for bit in range(1<<n):
        for i in range(n):
            if bit>>i&1:continue
            nbit=bit|1<<i
            dp[nbit]=max(dp[nbit],dp[bit]+sum(ss[j][i] for j in range(n) if bit>>j&1))
    print(dp[-1])

main()
0