結果

問題 No.90 品物の並び替え
ユーザー ynishimuraynishimura
提出日時 2021-01-28 14:30:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,582 ms / 5,000 ms
コード長 882 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-09-08 05:27:42
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,224 KB
testcase_01 AC 161 ms
8,272 KB
testcase_02 AC 17 ms
8,200 KB
testcase_03 AC 31 ms
8,120 KB
testcase_04 AC 32 ms
8,264 KB
testcase_05 AC 162 ms
8,312 KB
testcase_06 AC 159 ms
8,256 KB
testcase_07 AC 18 ms
8,068 KB
testcase_08 AC 16 ms
8,080 KB
testcase_09 AC 1,582 ms
8,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

# 入力
(n, m) = [int(i) for i in input().rstrip().split()]

def matrix():
    table = []
    for _ in range(n):
        table += [[0] * n]
    for _ in range(m):
        item1, item2, score = [int(x) for x in input().split()]
        # スコア表作成
        table[item1][item2] = score

    return table

def resolve(table):
    max_score = 0
    for val in itertools.permutations(range(n)): #順列を生成する
        score = 0
        for i in range(1, len(val)):
            for j in range(0, i):
                # スコア表に沿って得点を追加していく
                score += table[val[j]][val[i]]
        # 比較して大きい得点を格納
        max_score = max(score, max_score)
    return max_score


def main():
    table = matrix()
    max_score = resolve(table)
    print(max_score)

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