結果

問題 No.90 品物の並び替え
ユーザー GrayCoderGrayCoder
提出日時 2018-08-14 11:19:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,785 ms / 5,000 ms
コード長 615 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 11,732 KB
実行使用メモリ 9,960 KB
最終ジャッジ日時 2023-10-24 17:02:44
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,956 KB
testcase_01 AC 196 ms
9,960 KB
testcase_02 AC 28 ms
9,956 KB
testcase_03 AC 43 ms
9,956 KB
testcase_04 AC 43 ms
9,960 KB
testcase_05 AC 192 ms
9,960 KB
testcase_06 AC 191 ms
9,960 KB
testcase_07 AC 28 ms
9,956 KB
testcase_08 AC 26 ms
9,956 KB
testcase_09 AC 1,785 ms
9,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations
from sys import stdin, stdout

input = lambda: stdin.readline()
write = stdout.write

def main():
    N, M = map(int, input().split())
    I = [tuple(map(int, input().split())) for _ in range(M)]

    table = [[0] * N for _ in [0] * N]
    for i1, i2, s in I:
        table[i1][i2] = s

    def calc(n):
        ret = 0
        for i in range(N - 1):
            for j in range(i + 1, N):
                ret += table[n[i]][n[j]]
        return ret

    score = 0
    for n in permutations(range(N)):
        ret = calc(n)
        score = max(score, ret)
    print(score)

main()
0