結果

問題 No.691 E869120 and Constructing Array 5
ユーザー e869120e869120
提出日時 2018-05-17 21:29:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 1,000 ms
コード長 2,158 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 92,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:10:45
合計ジャッジ時間 10,530 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
4,376 KB
testcase_01 AC 251 ms
4,380 KB
testcase_02 AC 237 ms
4,376 KB
testcase_03 AC 242 ms
4,376 KB
testcase_04 AC 242 ms
4,376 KB
testcase_05 AC 240 ms
4,376 KB
testcase_06 AC 243 ms
4,376 KB
testcase_07 AC 230 ms
4,380 KB
testcase_08 AC 237 ms
4,376 KB
testcase_09 AC 248 ms
4,376 KB
testcase_10 AC 245 ms
4,380 KB
testcase_11 AC 241 ms
4,376 KB
testcase_12 AC 233 ms
4,380 KB
testcase_13 AC 233 ms
4,376 KB
testcase_14 AC 238 ms
4,380 KB
testcase_15 AC 242 ms
4,380 KB
testcase_16 AC 246 ms
4,380 KB
testcase_17 AC 240 ms
4,376 KB
testcase_18 AC 238 ms
4,380 KB
testcase_19 AC 231 ms
4,376 KB
testcase_20 AC 245 ms
4,380 KB
testcase_21 AC 246 ms
4,376 KB
testcase_22 AC 238 ms
4,376 KB
testcase_23 AC 238 ms
4,376 KB
testcase_24 AC 248 ms
4,376 KB
testcase_25 AC 237 ms
4,376 KB
testcase_26 AC 238 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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() <= 100) {
		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