結果

問題 No.691 E869120 and Constructing Array 5
ユーザー e869120e869120
提出日時 2018-05-17 21:29:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,157 bytes
コンパイル時間 1,076 ms
コンパイル使用メモリ 91,100 KB
実行使用メモリ 12,260 KB
最終ジャッジ日時 2023-09-10 22:39:58
合計ジャッジ時間 6,547 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

struct State {
	long double v; vector<int>t;
};
bool operator<(const State &a1, const State &a2) {
	if (a1.v < a2.v) return true;
	return false;
}

int Rand() {
	return (1 << 20)*(rand() % 1024) + (1 << 10)*(rand() % 1024) + (rand() % 1024);
}

vector<int>concatenate(vector<int>A1, vector<int>A2) {
	vector<int>I;
	for (int i = 0; i < A1.size(); i++) I.push_back(A1[i]);
	for (int i = 0; i < A2.size(); i++) I.push_back(A2[i]);
	return I;
}

vector<int>solve(long double T) {
	vector<State>F; int G1 = T / 8;
	while (F.size() <= 50) {
		int Y = Rand() % (G1*G1);
		long double I = (T / 8) - sqrtl(1.0L*Y);
		long double J = I*I; int K1 = J, K2 = K1 + 1;
		long double L1 = sqrtl(1.0L*Y) + sqrtl(1.0L*K1); if (abs(T / 8 - L1) <= 1.0e-4) { F.push_back(State{ L1, vector<int>{Y, K1} }); }
		long double L2 = sqrtl(1.0L*Y) + sqrtl(1.0L*K2); if (abs(T / 8 - L2) <= 1.0e-4) { F.push_back(State{ L2, vector<int>{Y, K2} }); }
	}
	sort(F.begin(), F.end()); long double EPS1 = T / 8, EPS = 1e-4;
	for (int i = 0; i < 3; i++) {
		vector<State>G; EPS1 *= 2.0L; EPS *= 0.01L;
		for (int j = 0; j < F.size(); j++) {
			long double R1 = (EPS1 - F[j].v);
			int pos1 = lower_bound(F.begin(), F.end(), State{ R1,vector<int>{} }) - F.begin();
			if (pos1 >= 1) {
				long double Y = F[pos1 - 1].v + F[j].v;
				if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1 - 1].t,F[j].t) });
			}
			if (pos1 < F.size()) {
				long double Y = F[pos1].v + F[j].v;
				if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1].t,F[j].t) });
			}
		}
		F = G;
		sort(F.begin(), F.end());
	}
	if (F.size() == 0) return vector<int>{};
	return F[0].t;
}

int main() {
	srand((unsigned)time(NULL));
	int Q; cin >> Q;
	for (int i = 1; i <= Q; i++) {
		long double P; cin >> P;
		vector<int>Z;
		while (true) {
			Z = solve(P); if (Z.size() >= 1) break;
		}
		long double E = 0;
		cout << Z.size(); for (int j = 0; j < Z.size(); j++) { cout << " " << Z[j]; E += sqrtl(1.0L*Z[j]); }cout << endl;

		//printf("score = %.13Lf\n", abs(P - E));
	}
	return 0;
}
0