結果

問題 No.5020 Averaging
ユーザー e869120e869120
提出日時 2024-02-19 18:58:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,732 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 83,756 KB
実行使用メモリ 6,676 KB
スコア 0
最終ジャッジ日時 2024-02-25 12:31:57
合計ジャッジ時間 48,877 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
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 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const long long Target = 500000000000000000LL;

void Operation(vector<long long>& A, vector<long long>& B, int idx1, int idx2) {
	long long avg1 = (A[idx1] + A[idx2]) / 2LL;
	long long avg2 = (B[idx1] + B[idx2]) / 2LL;
	A[idx1] = avg1; B[idx1] = avg2;
	A[idx2] = avg1; B[idx2] = avg2;
}

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

	// 準備
	long long RecordScore = (1LL << 60);
	int StartTime = clock();
	vector<pair<int, int>> Answer;

	// Step 2. ランダムな処理
	while (clock() - StartTime < 9 * CLOCKS_PER_SEC / 10) {
		vector<long long> C = A;
		vector<long long> D = B;
		vector<pair<int, int>> CurrentAns;
		for (int i = 0; i < 50; i++) {
			int idx1, idx2;
			while (true) {
				idx1 = rand() % (N - 1) + 1;
				idx2 = rand() % (N - 1) + 1;
				if (idx1 != idx2) break;
			}
			Operation(C, D, idx1, idx2);
			CurrentAns.push_back(make_pair(idx1, idx2));
		}

		// 誤差の計算
		long long MinV = (1LL << 60);
		long long MinID = -1;
		for (int i = 1; i < N; i++) {
			long long v1 = (C[0] + C[i]) / 2LL;
			long long v2 = (D[0] + D[i]) / 2LL;
			long long err = min(abs(v1 - Target), abs(v2 - Target));
			if (MinV > err) {
				MinV = err;
				MinID = i;
			}
		}
		CurrentAns.push_back(make_pair(0, MinID));

		// 記録と比較
		if (RecordScore > MinV) {
			RecordScore = MinV;
			Answer = CurrentAns;
		}
	}

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