結果

問題 No.90 品物の並び替え
ユーザー piconic_X
提出日時 2016-08-25 01:08:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,746 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-08 02:12:43
合計ジャッジ時間 3,324 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

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