結果

問題 No.3011 品物の並び替え (Extra)
ユーザー 古寺いろは古寺いろは
提出日時 2015-05-04 00:13:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 1,276 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 151,948 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 05:48:28
合計ジャッジ時間 4,891 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 250 ms
4,380 KB
testcase_01 AC 262 ms
4,376 KB
testcase_02 AC 281 ms
4,380 KB
testcase_03 AC 277 ms
4,380 KB
testcase_04 AC 263 ms
4,380 KB
testcase_05 AC 250 ms
4,376 KB
testcase_06 AC 252 ms
4,376 KB
testcase_07 AC 259 ms
4,376 KB
testcase_08 AC 283 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	
} 
0