結果
問題 | No.8011 品物の並び替え (Extra) |
ユーザー |
![]() |
提出日時 | 2015-05-04 00:13:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 273 ms / 5,000 ms |
コード長 | 1,276 bytes |
コンパイル時間 | 1,213 ms |
コンパイル使用メモリ | 165,976 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 18:06:40 |
合計ジャッジ時間 | 4,296 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 |
ソースコード
#include "bits/stdc++.h" using namespace std; int main() { int N, M; cin >> N >> M; vector<int> item1(M), item2(M), score(M); vector<vector<int>> point(N, vector<int>(N, 0)); for (int i = 0; i < M; i++) { cin >> item1[i] >> item2[i] >> score[i]; point[item1[i]][item2[i]] += score[i]; } int ans = -1; vector<int> ans2(M); for (int t = 0; t < 2000; t++) { vector<int> temp; int tempscore = 0; for (int i = 0; i < N; i++) { temp.push_back(i); } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { tempscore += point[i][j]; } } for (int i = 0; i < 2000; i++) { int ta = rand() % N; int tb = rand() % N; if (ta > tb) swap(ta, tb); if (ta == tb) continue; int a = temp[ta]; int b = temp[tb]; //swap(temp[ta], temp[tb]); int add = 0; for (int j = ta + 1; j < tb; j++) { add -= point[a][temp[j]]; add += point[temp[j]][a]; add += point[b][temp[j]]; add -= point[temp[j]][b]; } add -= point[a][b]; add += point[b][a]; if (add>0){ swap(temp[ta], temp[tb]); tempscore += add; } } if (ans < tempscore){ ans = tempscore; ans2 = temp; } } cout << ans << endl; for (int i = 0; i < N; i++) { cout << ans2[i] << endl; } cin >> N; }