結果

問題 No.90 品物の並び替え
ユーザー piconic_Xpiconic_X
提出日時 2016-08-25 01:08:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,683 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-25 15:12:19
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 188 ms
10,752 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 45 ms
10,752 KB
testcase_04 AC 47 ms
10,752 KB
testcase_05 AC 189 ms
10,880 KB
testcase_06 AC 188 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 1,683 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations

def eval_(N, regs, t):
    score = 0
    for i in range(N):
        r = regs[t[i]]
        for tj in t[i:]:
            score += r[tj]
    return score

def solve(N, regs):
    max_ = 0
    for t in permutations(range(N)):
        max_ = max(max_, eval_(N, regs, t))
    return max_

def main():
    N, M = map(int, input().split())
    regs = [[0 for i in range(N)] for j in range(N)]
    for k in range(M):
        i1, i2, score = map(int, input().split())
        regs[i1][i2] = score
    print(solve(N, regs))

main()
0