結果

問題 No.90 品物の並び替え
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-08 20:33:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,920 KB
最終ジャッジ日時 2023-09-25 07:16:35
合計ジャッジ時間 1,267 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
8,748 KB
testcase_01 WA -
testcase_02 AC 24 ms
8,808 KB
testcase_03 AC 30 ms
8,820 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 32 ms
8,920 KB
testcase_07 AC 28 ms
8,884 KB
testcase_08 AC 25 ms
8,820 KB
testcase_09 AC 33 ms
8,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

def read_data():
    N, M = map(int, input().split())
    score = [[0]*N for i in range(N)]
    for m in range(M):
        a, b, s = map(int, input().split())
        score[a][b] = s
    return N, M, score


def solve(N, M, score):
    sol = list(range(N))
    total = calc_score(sol, score)
    delta = 10**6
    r = 0.995
    record = total
    while int(delta):
        delta *= r
        a = random.randint(0, N-1)
        b = random.randint(0, N-1)
        if a == b:
            continue
        sol[a], sol[b] = sol[b], sol[a]
        new_total = calc_score(sol, score)
        if new_total + delta < total:
            sol[a], sol[b] = sol[b], sol[a]
        else:
            if new_total > record:
                record = new_total
            total = new_total
    return record


def calc_score(sol, score):
    n = len(sol)
    total = 0
    for i in range(n-1):
        score_i = score[sol[i]]
        for j in range(i+1, n):
            total += score_i[sol[j]]
    return total

if __name__ == '__main__':
    N, M, score = read_data()
    print(solve(N, M, score))
0