結果
問題 | No.8011 品物の並び替え (Extra) |
ユーザー |
|
提出日時 | 2015-05-04 04:33:10 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 222 ms / 5,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-05 18:51:36 |
合計ジャッジ時間 | 2,267 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 |
ソースコード
import randomdef read_data():N, M = map(int, input().split())score = [[0] * N for i in range(N)]for i in range(M):a, b, s = map(int, input().split())score[a][b] = sreturn N, M, scoredef solve(N, M, score):sol = list(range(N))total = calc_score(sol, score)delta = 10**6r = 0.995record = totalbest_sol = sol[:]while int(delta):delta *= ra = random.randint(0, N-1)b = random.randint(0, N-1)if a == b:continuesol[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_totalbest_sol = sol[:]total = new_totalreturn record, best_soldef calc_score(sol, score):n = len(sol)total = 0for i in range(n-1):score_i = score[sol[i]]for j in range(i+1, n):total += score_i[sol[j]]return totalif __name__ == '__main__':N, M, score = read_data()# N, M = 50, 50 * 49# score = [[random.randint(0, 10000) for j in range(N)] for i in range(N)]total, solution = solve(N, M, score)print(total)print(' '.join(map(str, solution)))