結果

問題 No.3011 品物の並び替え (Extra)
ユーザー kurenai3110kurenai3110
提出日時 2017-06-10 03:26:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,003 ms / 5,000 ms
コード長 2,347 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 73,028 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 05:30:38
合計ジャッジ時間 11,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,002 ms
4,348 KB
testcase_01 AC 1,002 ms
4,348 KB
testcase_02 AC 1,002 ms
4,348 KB
testcase_03 AC 1,002 ms
4,348 KB
testcase_04 AC 1,002 ms
4,348 KB
testcase_05 AC 1,002 ms
4,348 KB
testcase_06 AC 1,001 ms
4,348 KB
testcase_07 AC 1,003 ms
4,348 KB
testcase_08 AC 1,002 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <chrono>
#include <cmath>
using namespace std;

#define LIMIT 1.0

class Timer {
	chrono::high_resolution_clock::time_point start, end;
	double limit;

public:
	Timer() {
		start = chrono::high_resolution_clock::now();
	}
	Timer(double l) {
		start = chrono::high_resolution_clock::now();
		limit = l;
	}

	double getTime() {
		end = chrono::high_resolution_clock::now();
		return chrono::duration<double>(end - start).count();
	}

	bool Over() {
		if (getTime() > limit) {
			return true;
		}
		return false;
	}

	void setLimit(double l) {
		limit = l;
	}
	void setStart() { start = chrono::high_resolution_clock::now(); }
};

class Xor128 {
	unsigned static int x, y, z, w;
public:
	Xor128() {
		x = 31103110, y = 123456789, z = 521288629, w = 88675123;
	}

	unsigned int rand()
	{
		unsigned int t;
		t = (x ^ (x << 11)); x = y; y = z; z = w;
		return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
	}
};
unsigned int Xor128::x, Xor128::y, Xor128::z, Xor128::w;


int N, M;
int Score[50][50];

int nowScore(vector<int>&items) {
	int score = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			score += Score[items[i]][items[j]];
		}
	}

	return score;
}

int main()
{
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b, c; cin >> a >> b >> c;
		Score[a][b] = c;
	}

	vector<int>items(N);
	for (int i = 0; i < N; i++) {
		items[i] = i;
	}

	int nowscore = nowScore(items);

	int maxscore = nowscore;
	vector<int>ans(items);

	Xor128 xor128;
	Timer tmr(LIMIT);
	while (!tmr.Over()) {
		int p1, p2;
		p1 = xor128.rand() % N;
		p2 = xor128.rand() % N;

		swap(items[p1], items[p2]);
		int tmpscore = nowScore(items);

		double starttemp = 100;
		double endtemp = 10;
		double t = tmr.getTime();
		double temp = starttemp - (starttemp - endtemp) * t / LIMIT;
		cerr << exp((tmpscore - nowscore) / temp) << endl;
		if (exp((tmpscore - nowscore) / temp) > (double)xor128.rand() / UINT32_MAX) {
			nowscore = tmpscore;

			if (nowscore > maxscore) {
				maxscore = nowscore;
				ans = items;
			}
		}
		else {
			swap(items[p1], items[p2]);
		}
	}

	cout << maxscore << endl;
	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		cout << ans[i];
	}
	cout << endl;

	cout << "多分これが一番良いと思います" << endl;

    return 0;
}

0