結果

問題 No.5020 Averaging
ユーザー square1001square1001
提出日時 2024-02-25 15:33:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 899 ms / 1,000 ms
コード長 2,510 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 216,424 KB
実行使用メモリ 179,924 KB
スコア 83,698,298
最終ジャッジ日時 2024-02-25 15:34:14
合計ジャッジ時間 50,697 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 855 ms
179,924 KB
testcase_01 AC 873 ms
179,924 KB
testcase_02 AC 854 ms
179,924 KB
testcase_03 AC 877 ms
179,924 KB
testcase_04 AC 854 ms
179,924 KB
testcase_05 AC 875 ms
179,924 KB
testcase_06 AC 874 ms
179,924 KB
testcase_07 AC 880 ms
179,924 KB
testcase_08 AC 849 ms
179,924 KB
testcase_09 AC 883 ms
179,924 KB
testcase_10 AC 877 ms
179,924 KB
testcase_11 AC 850 ms
179,924 KB
testcase_12 AC 874 ms
179,924 KB
testcase_13 AC 878 ms
179,924 KB
testcase_14 AC 849 ms
179,924 KB
testcase_15 AC 880 ms
179,924 KB
testcase_16 AC 873 ms
179,924 KB
testcase_17 AC 848 ms
179,924 KB
testcase_18 AC 882 ms
179,924 KB
testcase_19 AC 880 ms
179,924 KB
testcase_20 AC 852 ms
179,924 KB
testcase_21 AC 878 ms
179,924 KB
testcase_22 AC 877 ms
179,924 KB
testcase_23 AC 848 ms
179,924 KB
testcase_24 AC 876 ms
179,924 KB
testcase_25 AC 871 ms
179,924 KB
testcase_26 AC 854 ms
179,924 KB
testcase_27 AC 881 ms
179,924 KB
testcase_28 AC 879 ms
179,924 KB
testcase_29 AC 855 ms
179,924 KB
testcase_30 AC 872 ms
179,924 KB
testcase_31 AC 899 ms
179,924 KB
testcase_32 AC 872 ms
179,924 KB
testcase_33 AC 849 ms
179,924 KB
testcase_34 AC 880 ms
179,924 KB
testcase_35 AC 895 ms
179,924 KB
testcase_36 AC 847 ms
179,924 KB
testcase_37 AC 898 ms
179,924 KB
testcase_38 AC 874 ms
179,924 KB
testcase_39 AC 851 ms
179,924 KB
testcase_40 AC 884 ms
179,924 KB
testcase_41 AC 871 ms
179,924 KB
testcase_42 AC 844 ms
179,924 KB
testcase_43 AC 867 ms
179,924 KB
testcase_44 AC 870 ms
179,924 KB
testcase_45 AC 843 ms
179,924 KB
testcase_46 AC 889 ms
179,924 KB
testcase_47 AC 877 ms
179,924 KB
testcase_48 AC 846 ms
179,924 KB
testcase_49 AC 865 ms
179,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

class state {
public:
	double x, y; uint64_t bit; int pre;
	state() : x(0.0), y(0.0), bit(0), pre(-1) {}
	state(double x_, double y_, uint64_t bit_, int pre_) : x(x_), y(y_), bit(bit_), pre(pre_) {}
	double score() const {
		return max(abs(x), abs(y));
	}
	bool operator<(const state& s) const {
		return score() < s.score();
	}
};

int main() {
	// step #1. input
	int N;
	cin >> N;
	vector<double> A(N), B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		A[i] -= 5.0e+17;
		B[i] -= 5.0e+17;
	}
	
	// step #2. beam search
	const int BEAMWIDTH = 6000;
	vector<vector<state> > beam(N - 2);
	for (int v1 = 1; v1 < N; v1++) {
		for (int v2 = v1 + 1; v2 < N; v2++) {
			double x = (A[0] + A[v1] + A[v2]) / 4;
			double y = (B[0] + B[v1] + B[v2]) / 4;
			uint64_t bit = ((1ULL << N) - 1) ^ (1ULL << 0) ^ (1ULL << v1) ^ (1ULL << v2);
			beam[0].push_back(state(x, y, bit, -1));
		}
	}
	sort(beam[0].begin(), beam[0].end());
	if (int(beam[0].size()) > BEAMWIDTH) {
		beam[0].resize(BEAMWIDTH);
	}
	for (int level = 1; level <= N - 3; level++) {
		double mul = pow(0.5, level != N - 3 ? level + 2 : N - 2);
		for (int i = 0; i < int(beam[level - 1].size()); i++) {
			state s = beam[level - 1][i];
			uint64_t b = s.bit;
			while (b != 0) {
				int pos = __builtin_ctzll(b);
				b ^= 1ULL << pos;
				double x = s.x + A[pos] * mul;
				double y = s.y + B[pos] * mul;
				uint64_t bit = s.bit ^ (1ULL << pos);
				beam[level].push_back(state(x, y, bit, i));
			}
		}
		sort(beam[level].begin(), beam[level].end());
		if (int(beam[level].size()) > BEAMWIDTH) {
			beam[level].resize(BEAMWIDTH);
		}
		cerr << "level = " << level << ": size = " << beam[level].size() << ", score = " << beam[level][0].score() << endl;
	}
	
	// step #3. reconstruction
	int pos = 0;
	vector<uint64_t> track;
	for (int level = N - 3; level >= 1; level--) {
		uint64_t b = beam[level][pos].bit;
		pos = beam[level][pos].pre;
		track.push_back(b);
	}
	track.push_back(beam[0][pos].bit);
	vector<int> ord;
	for (int i = 0; i < N - 3; i++) {
		uint64_t b = track[i] ^ track[i + 1];
		int pos = __builtin_ctzll(b);
		ord.push_back(pos);
	}
	for (int i = N - 1; i >= 0; i--) {
		if (!((track[N - 3] >> i) & 1)) {
			ord.push_back(i);
		}
	}
	cout << N - 1 << endl;
	for (int i = 0; i < N - 3; i++) {
		cout << ord[i] + 1 << ' ' << ord[i + 1] + 1 << endl;
	}
	cout << ord[N - 2] + 1 << ' ' << ord[N - 1] + 1 << endl;
	cout << ord[N - 3] + 1 << ' ' << ord[N - 1] + 1 << endl;
	
	return 0;
}
0