結果

問題 No.519 アイドルユニット
ユーザー kurenai3110kurenai3110
提出日時 2017-05-28 23:07:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 902 ms / 1,000 ms
コード長 3,095 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 06:36:02
合計ジャッジ時間 33,513 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 902 ms
6,812 KB
testcase_01 AC 901 ms
6,944 KB
testcase_02 AC 902 ms
6,940 KB
testcase_03 AC 902 ms
6,944 KB
testcase_04 AC 902 ms
6,944 KB
testcase_05 AC 902 ms
6,944 KB
testcase_06 AC 901 ms
6,944 KB
testcase_07 AC 902 ms
6,944 KB
testcase_08 AC 902 ms
6,940 KB
testcase_09 AC 902 ms
6,940 KB
testcase_10 AC 902 ms
6,940 KB
testcase_11 AC 902 ms
6,944 KB
testcase_12 AC 902 ms
6,940 KB
testcase_13 AC 902 ms
6,940 KB
testcase_14 AC 902 ms
6,940 KB
testcase_15 AC 902 ms
6,944 KB
testcase_16 AC 902 ms
6,944 KB
testcase_17 AC 902 ms
6,940 KB
testcase_18 AC 902 ms
6,944 KB
testcase_19 AC 901 ms
6,944 KB
testcase_20 AC 902 ms
6,940 KB
testcase_21 AC 902 ms
6,940 KB
testcase_22 AC 902 ms
6,940 KB
testcase_23 AC 902 ms
6,940 KB
testcase_24 AC 902 ms
6,944 KB
testcase_25 AC 902 ms
6,940 KB
testcase_26 AC 902 ms
6,940 KB
testcase_27 AC 901 ms
6,944 KB
testcase_28 AC 902 ms
6,944 KB
testcase_29 AC 902 ms
6,940 KB
testcase_30 AC 902 ms
6,944 KB
testcase_31 AC 902 ms
6,940 KB
testcase_32 AC 901 ms
6,940 KB
testcase_33 AC 902 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class RandomXor {
	unsigned static int x, y, z, w;
public:
	RandomXor() {
		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 RandomXor::x, RandomXor::y, RandomXor::z, RandomXor::w;


int main()
{
	auto start = chrono::system_clock::now();
	RandomXor rx;
	int N; cin >> N;
	vector<vector<int>>LOVE(N);
	for (int i = 0; i < N; i++) {
		LOVE[i].resize(N);
		for (int j = 0; j < N; j++) {
			cin >> LOVE[i][j];
		}
	}

	int P = N / 2;
	vector<pair<int, int>>Pi(P);
	int maxLOVE = 0,tmpLOVE=0;
	for (int i = 0; i < P; i++) {
		Pi[i] = make_pair(2 * i, 2 * i + 1);
		tmpLOVE += LOVE[2 * i][2 * i + 1];
	}
	maxLOVE = tmpLOVE;

	double startTemp = 100;
	double endTemp = 10;
	double T = 0.9;
	while (1) {
		auto end = chrono::system_clock::now();
		double t = chrono::duration<double>(end - start).count();
		if (t > 0.9)break;

		int r1, r2;
		r1 = rx.rand() % P;
		r2 = rx.rand() % P;
		if (r1 == r2)continue;

		double temp = startTemp + (endTemp - startTemp) * t / T;
		double probability = exp(-50. / temp);
		//cerr << probability << endl;

		pair<int, int>p1 = Pi[r1], p2 = Pi[r2];
		if (tmpLOVE < tmpLOVE - LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p1.first][p2.first] + LOVE[p1.second][p2.second]) {
			tmpLOVE += -LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p1.first][p2.first] + LOVE[p1.second][p2.second];
			maxLOVE = max(maxLOVE, tmpLOVE);
			swap(Pi[r1].second, Pi[r2].first);
		}
		else if (tmpLOVE < tmpLOVE - LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p1.first][p2.second] + LOVE[p2.first][p1.second]) {
			tmpLOVE += -LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p1.first][p2.second] + LOVE[p2.first][p1.second];
			maxLOVE = max(maxLOVE, tmpLOVE);
			swap(Pi[r1].second, Pi[r2].second);
		}
		else if (tmpLOVE < tmpLOVE - LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p2.first][p1.second] + LOVE[p1.first][p2.second]) {
			tmpLOVE += -LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p2.second][p1.second] + LOVE[p2.first][p1.first];
			maxLOVE = max(maxLOVE, tmpLOVE);
			swap(Pi[r1].first, Pi[r2].second);
		}
		else if (tmpLOVE < tmpLOVE - LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p2.first][p1.second] + LOVE[p1.first][p2.second]) {
			tmpLOVE += -LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p2.first][p1.second] + LOVE[p1.first][p2.second];
			maxLOVE = max(maxLOVE, tmpLOVE);
			swap(Pi[r1].first, Pi[r2].first);
		}
		else if ((double)rx.rand() / UINT32_MAX < probability) {
			tmpLOVE += -LOVE[p1.first][p1.second] - LOVE[p2.first][p2.second] + LOVE[p1.first][p2.first] + LOVE[p1.second][p2.second];
			maxLOVE = max(maxLOVE, tmpLOVE);
			swap(Pi[r1].second, Pi[r2].first);
		}
	}

	cout << maxLOVE << endl;


    return 0;
}

0