結果

問題 No.519 アイドルユニット
ユーザー kurenai3110kurenai3110
提出日時 2017-05-28 22:57:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,644 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 76,900 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:31:04
合計ジャッジ時間 33,893 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <chrono>
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()
{
	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;

	auto start = chrono::system_clock::now();
	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;

		pair<int, int>p1 = Pi[r1], p2 = Pi[r2];
		cerr << tmpLOVE << endl;
		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);
		}
	}

	cout << maxLOVE << endl;


    return 0;
}

0