結果

問題 No.691 E869120 and Constructing Array 5
ユーザー yosupotyosupot
提出日時 2018-05-18 23:23:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 420 ms / 1,000 ms
コード長 2,816 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 116,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:11:03
合計ジャッジ時間 11,873 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 420 ms
4,376 KB
testcase_01 AC 411 ms
4,380 KB
testcase_02 AC 299 ms
4,376 KB
testcase_03 AC 294 ms
4,376 KB
testcase_04 AC 290 ms
4,380 KB
testcase_05 AC 291 ms
4,376 KB
testcase_06 AC 293 ms
4,376 KB
testcase_07 AC 285 ms
4,376 KB
testcase_08 AC 302 ms
4,376 KB
testcase_09 AC 285 ms
4,376 KB
testcase_10 AC 298 ms
4,380 KB
testcase_11 AC 294 ms
4,380 KB
testcase_12 AC 308 ms
4,376 KB
testcase_13 AC 293 ms
4,376 KB
testcase_14 AC 298 ms
4,376 KB
testcase_15 AC 304 ms
4,380 KB
testcase_16 AC 291 ms
4,376 KB
testcase_17 AC 287 ms
4,380 KB
testcase_18 AC 298 ms
4,380 KB
testcase_19 AC 299 ms
4,376 KB
testcase_20 AC 290 ms
4,380 KB
testcase_21 AC 299 ms
4,380 KB
testcase_22 AC 300 ms
4,380 KB
testcase_23 AC 289 ms
4,376 KB
testcase_24 AC 285 ms
4,376 KB
testcase_25 AC 299 ms
4,376 KB
testcase_26 AC 299 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0