結果

問題 No.5020 Averaging
ユーザー e869120e869120
提出日時 2024-02-21 12:12:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 858 ms / 1,000 ms
コード長 1,817 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 79,544 KB
実行使用メモリ 6,676 KB
スコア 81,790,066
最終ジャッジ日時 2024-02-25 12:49:57
合計ジャッジ時間 46,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 856 ms
6,676 KB
testcase_01 AC 857 ms
6,676 KB
testcase_02 AC 856 ms
6,676 KB
testcase_03 AC 856 ms
6,676 KB
testcase_04 AC 856 ms
6,676 KB
testcase_05 AC 855 ms
6,676 KB
testcase_06 AC 856 ms
6,676 KB
testcase_07 AC 856 ms
6,676 KB
testcase_08 AC 855 ms
6,676 KB
testcase_09 AC 856 ms
6,676 KB
testcase_10 AC 856 ms
6,676 KB
testcase_11 AC 856 ms
6,676 KB
testcase_12 AC 855 ms
6,676 KB
testcase_13 AC 856 ms
6,676 KB
testcase_14 AC 856 ms
6,676 KB
testcase_15 AC 856 ms
6,676 KB
testcase_16 AC 854 ms
6,676 KB
testcase_17 AC 856 ms
6,676 KB
testcase_18 AC 856 ms
6,676 KB
testcase_19 AC 856 ms
6,676 KB
testcase_20 AC 855 ms
6,676 KB
testcase_21 AC 856 ms
6,676 KB
testcase_22 AC 856 ms
6,676 KB
testcase_23 AC 855 ms
6,676 KB
testcase_24 AC 855 ms
6,676 KB
testcase_25 AC 855 ms
6,676 KB
testcase_26 AC 856 ms
6,676 KB
testcase_27 AC 854 ms
6,676 KB
testcase_28 AC 856 ms
6,676 KB
testcase_29 AC 855 ms
6,676 KB
testcase_30 AC 855 ms
6,676 KB
testcase_31 AC 858 ms
6,676 KB
testcase_32 AC 855 ms
6,676 KB
testcase_33 AC 856 ms
6,676 KB
testcase_34 AC 856 ms
6,676 KB
testcase_35 AC 856 ms
6,676 KB
testcase_36 AC 855 ms
6,676 KB
testcase_37 AC 856 ms
6,676 KB
testcase_38 AC 856 ms
6,676 KB
testcase_39 AC 856 ms
6,676 KB
testcase_40 AC 856 ms
6,676 KB
testcase_41 AC 856 ms
6,676 KB
testcase_42 AC 858 ms
6,676 KB
testcase_43 AC 856 ms
6,676 KB
testcase_44 AC 858 ms
6,676 KB
testcase_45 AC 856 ms
6,676 KB
testcase_46 AC 857 ms
6,676 KB
testcase_47 AC 856 ms
6,676 KB
testcase_48 AC 856 ms
6,676 KB
testcase_49 AC 856 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long long Target = 500000000000000000LL;
long long N;
long long A[59];
long long B[59];
long long Order[59];
long long BestOrder[59];

long long GetScore() {
	long long TotalScore1 = (A[1] >> (N - 1));
	long long TotalScore2 = (B[1] >> (N - 1));
	for (int i = 1; i <= N - 1; i++) TotalScore1 += (A[Order[i]] >> (N - i));
	for (int i = 1; i <= N - 1; i++) TotalScore2 += (B[Order[i]] >> (N - i));
	return max(abs(Target - TotalScore1), abs(Target - TotalScore2));
}

long double Randouble() {
	double s = 0.0, t = 1.0;
	for (int i = 0; i < 3; i++) {
		t /= 1024.0;
		s += 1.0 * (rand() % 1024) * t;
	}
	return s;
}

int main() {
	// Step 1. 入力
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];

	// Step 2. 山登り法
	for (int i = 1; i <= N - 1; i++) Order[i] = i + 1;
	long long CurrentScore = GetScore();
	long long BestScore = CurrentScore;
	int StartTime = clock();
	while (clock() - StartTime <= 85 * CLOCKS_PER_SEC / 100) {
		int idx1 = rand() % (N - 1) + 1;
		int idx2 = rand() % (N - 1) + 1;
		swap(Order[idx1], Order[idx2]);
		long long CandScore = GetScore();
		double Diff = log10(CurrentScore) - log10(CandScore);
		if (Randouble() < exp(Diff / 0.17)) {
			if (BestScore > CandScore) {
				BestScore = CandScore;
				for (int i = 1; i <= N; i++) BestOrder[i] = Order[i];
			}
			CurrentScore = CandScore;
		}
		else {
			swap(Order[idx1], Order[idx2]);
		}
	}

	// Step 3. 答えを得る
	vector<pair<int, int>> Answer;
	for (int i = 1; i <= N - 1; i++) Answer.push_back(make_pair(1, BestOrder[i]));

	// Step 4. 出力
	cout << Answer.size() << endl;
	for (int i = 0; i < Answer.size(); i++) cout << Answer[i].first << " " << Answer[i].second << endl;
	return 0;
}
0