結果

問題 No.90 品物の並び替え
ユーザー fgshunfgshun
提出日時 2020-09-27 10:07:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,897 ms / 5,000 ms
コード長 627 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 10,720 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-09-13 00:30:17
合計ジャッジ時間 3,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,072 KB
testcase_01 AC 193 ms
8,056 KB
testcase_02 AC 15 ms
8,088 KB
testcase_03 AC 35 ms
8,040 KB
testcase_04 AC 34 ms
8,064 KB
testcase_05 AC 194 ms
8,020 KB
testcase_06 AC 194 ms
8,068 KB
testcase_07 AC 18 ms
8,064 KB
testcase_08 AC 16 ms
8,040 KB
testcase_09 AC 1,897 ms
8,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import itertools

def resolve(in_):
    N, M = map(int, next(in_).split())

    scores = [[0] * N for _ in range(N)]
    for item1, item2, score in (map(int, line.split()) for line in itertools.islice(in_, M)):
        scores[item1][item2] = score

    ans = 0
    for _items in itertools.permutations(range(N)):
        temp = 0
        for i, item1 in enumerate(_items, 1):
            for item2 in _items[i:]:
                temp += scores[item1][item2]
            ans = max(ans, temp)
    return ans
    

def main():
    ans = resolve(sys.stdin.buffer)

    print(ans)


if __name__ == '__main__':
    main()
0