結果
| 問題 |
No.691 E869120 and Constructing Array 5
|
| ユーザー |
yosupot
|
| 提出日時 | 2018-05-18 23:23:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 413 ms / 1,000 ms |
| コード長 | 2,816 bytes |
| コンパイル時間 | 1,122 ms |
| コンパイル使用メモリ | 117,228 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 14:48:40 |
| 合計ジャッジ時間 | 11,470 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
using D = long double;
ll rand_int(ll l, ll r) { //[l, r]
using Di = uniform_int_distribution<ll>;
static random_device rd;
static mt19937 gen(rd());
return Di(l, r)(gen);
}
D calc(V<ll> v) {
D sm = 0;
for (ll d: v) sm += sqrt(D(d));
return sm;
}
const int M = 30;
V<ll> solve(D _x) {
V<ll> v_base;
{
v_base.push_back(1842018);
v_base.push_back(1842018);
v_base.push_back(1160398);
v_base.push_back(1160398);
v_base.push_back(731005);
v_base.push_back(731005);
D x = _x - calc(v_base);
for (int i = 6; i < 30; i++) {
D y = x/(M-i);
v_base.push_back(ll(y*y));
x -= sqrt(v_base.back());
}
v_base.back()++;
}
while (true) {
V<ll> v = v_base;
D x = calc(v) - _x;
for (int ph = 0; ph < 2000; ph++) {
int i = rand_int(6, M-1);
int j = rand_int(6, M-1);
if (i == j) continue;
if (v[i] > v[j]) swap(v[i], v[j]);
D a = sqrt(D(v[i])) + sqrt(D(v[j]));
D b = sqrt(D(v[i]-1)) + sqrt(D(v[j]+1));
if (x < a-b) continue;
v[i]--; v[j]++;
x -= (a-b);
}
x = calc(v) - _x;
for (int z = 2; z >= 0; z--) {
while (true) {
int i = 2*z;
int j = 2*z+1;
D a = sqrt(D(v[i])) + sqrt(D(v[j]));
D b = sqrt(D(v[i]-1)) + sqrt(D(v[j]+1));
if (x < a-b) break;;
v[i]--; v[j]++;
x -= (a-b);
}
}
if (abs(calc(v) - _x) < 0.95e-10) {
return v;
}
}
assert(false);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
// for (int ph = 0; ph < 1000; ph++) {
// solve(10000);
// }
// return 0;
int q;
cin >> q;
for (int ph = 0; ph < q; ph++) {
D x;
cin >> x;
auto v = solve(x);
// cout << x << " " << calc(v) << endl;
// cout << abs(x - calc(v)) << endl;
cout << v.size();
for (auto d: v) {
cout << " " << d;
} cout << endl;
}
return 0;
}
yosupot