結果

問題 No.90 品物の並び替え
ユーザー kutsutamakutsutama
提出日時 2018-12-23 05:47:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 778 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 10,064 KB
最終ジャッジ日時 2023-10-26 02:24:45
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,064 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def calc(order, table):
    score = 0
    it1, it2, sc = 0, 1, 2
    for tb in table:
        if order[tb[it1]] < order[tb[it2]]:
            score += tb[sc]
    return score

def solve(order, idx, used, score, table):
    if idx == n:
        score = calc(order, table)
    else:
        for i in range(len(used)):
            if not used[i]:
                used[i] = True
                order[i] = idx
                score = max(solve(order, idx + 1, used, score, table), score)
            used[i] = False
            order[i] = -1
    return score

n, m = [int(x) for x in input().split()]
tb = []
for i in range(m):
    tb += [[int(x) for x in input().split()]]

order = [-1] * n
used = [False] * n
score = solve(order, 0, used, 0, tb)

print(score)
0