結果

問題 No.90 品物の並び替え
ユーザー na-shna-sh
提出日時 2019-07-11 13:18:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 579 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-04-25 05:49:33
合計ジャッジ時間 12,526 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 1,797 ms
10,624 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 136 ms
10,624 KB
testcase_04 AC 212 ms
10,624 KB
testcase_05 AC 2,141 ms
10,624 KB
testcase_06 AC 1,463 ms
10,496 KB
testcase_07 AC 46 ms
10,752 KB
testcase_08 AC 26 ms
10,752 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

tab = []
for i in range(M):
    tab.append(list(map(int, input().split())))


def calc(x):
    ans = 0
    for row in tab:
        if all(c in x for c in row[:2]):
            if x.index(row[0]) < x.index(row[1]):
                ans += row[2]
    return ans

cnt = 1
for i in range(N):
    cnt *= i + 1

mx = 0
for i in range(cnt):
    lst = [j for j in range(N)]
    cdt = [None] * N
    x = i
    for j in range(N):
        x, m = divmod(x, len(lst))
        cdt[j] = lst.pop(m)
    cdt = calc(cdt)
    if cdt > mx:
        mx = cdt
print(mx)
0