結果

問題 No.90 品物の並び替え
ユーザー sdadssdads
提出日時 2019-02-01 17:17:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 63,488 KB
最終ジャッジ日時 2024-05-02 04:12:26
合計ジャッジ時間 14,970 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,752 KB
testcase_01 AC 2,687 ms
17,152 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 160 ms
11,520 KB
testcase_04 AC 263 ms
11,520 KB
testcase_05 AC 3,056 ms
17,152 KB
testcase_06 AC 2,034 ms
17,152 KB
testcase_07 AC 50 ms
10,880 KB
testcase_08 AC 26 ms
10,880 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

item1 = []
item2 = []

N, M = list(map(int, input().split()))

score_book = [[0 for i in range(N)] for j in range(N)]

for n in range(M):
    i, j, k = list(map(int, input().split()))
    item1.append(i)
    item2.append(j)
    score_book[item1[n]][item2[n]] = k

#全てのパターンを網羅する。
combi = list(itertools.permutations([i for i in range(N)], N))

#全通りのスコアを入れる配列を作る
score_table = [0 for i in range(len(combi))]

for i in range(len(combi)): 
    for j in range(N - 1):
        for m in range(M):
            if combi[i][j] == item1[m]:
                #組み合わせの先頭で一致すれば、後ろはどの組み合わせでも問題ない
                if j == 0:
                    score_table[i] = score_table[i] + score_book[item1[m]][item2[m]]
                    continue
                for k in range(j + 1, N):
                    if combi[i][k] == item2[m]:
                        score_table[i] = score_table[i] + score_book[item1[m]][item2[m]]
    
print(max(score_table))
0