結果

問題 No.456 Millions of Submits!
ユーザー はむこ
提出日時 2017-05-17 13:37:33
言語 C++11
(gcc 4.8.5)
結果
RE  
実行時間 -
コード長 2157 Byte
コンパイル時間 1943 ms
使用メモリ 32984 KB

ソースコード

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if (!v.empty()) { o << '['; copy(v.begin(), v.end(), ostream_iterator<T>(o, ", ")); o << "\b\b]"; } return o; }
using ll = long long;  using vll = vector<ll>; using vi = vector<int>;
typedef pair<ll, ll> P;

static const double EPS = 1e-14;
static const long long INF = 1e18;
#define MAX_N 100005

ll m;
vll av, bv; vector<double> tv, ret;

void solve(ll i) {
    int a = av[i], b = bv[i]; 
    double t = tv[i];
    if (!a) {
        ret[i] = exp(pow(t, 1.0 / b));
        return;
    }
    if (!b) {
        ret[i] = pow(t, 1.0 / a);
        return;
    }

    double rl = 1e-12;
    double rr = 11;
    double prev_m = 100;
    while (1) {
        double m = (rl + rr) / 2;
        if (abs(prev_m - m) < 1e-10) break;
        (pow(m, a) * pow(log(m), b) - t > 0) ? rr = m : rl = m;
        prev_m = m;
    }
    double n = rl;
    ret[i] = n;
}

void parallel_rep(int n, function<void(ll)> f, ll thnum = 50) {
    vll range(thnum);
    rep(i, thnum) range[i] = i * m / thnum;
    range.pb(m);
    vector<thread> t(thnum);
    rep(i, thnum) {
        t[i] = thread([&](ll l, ll r){ repi(j, l, r) solve(j); }, range[i], range[i+1]);
    }
    rep(i, thnum) {
        t[i].join();
    }
}

int main(void) {
    scanf("%lld", &m);
    av.resize(m);
    bv.resize(m);
    tv.resize(m);
    ret.resize(m);
    rep(i, m) {
        scanf("%lld %lld", &av[i], &bv[i]);
        scanf("%lf", &tv[i]);
    }

    parallel_rep(m, solve, 100);
    rep(i, m) {
        printf("%.10f\n", ret[i]);
    }


    return 0;
}
0