結果

問題 No.456 Millions of Submits!
ユーザー pekempeypekempey
提出日時 2016-12-08 19:57:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 4,500 ms
コード長 2,541 bytes
コンパイル時間 6,002 ms
コンパイル使用メモリ 180,904 KB
実行使用メモリ 5,072 KB
最終ジャッジ日時 2023-09-05 20:49:32
合計ジャッジ時間 10,770 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,808 KB
testcase_01 AC 4 ms
4,776 KB
testcase_02 AC 5 ms
4,804 KB
testcase_03 AC 4 ms
4,816 KB
testcase_04 AC 5 ms
4,816 KB
testcase_05 AC 4 ms
4,904 KB
testcase_06 AC 5 ms
4,716 KB
testcase_07 AC 4 ms
5,072 KB
testcase_08 AC 4 ms
4,752 KB
testcase_09 AC 7 ms
4,832 KB
testcase_10 AC 7 ms
4,816 KB
testcase_11 AC 30 ms
4,820 KB
testcase_12 AC 261 ms
4,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC optimize ("fast-math")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;

const int N = 1 << 17;
const double lte = -4 * log(10);
double lg[N + 2];
double ex[20202];

double fastexp(double x) {
    return exp(x);
    //int a = floor(x * 1e3);
    //double b = x - a * 1e-3;
    //return ex[a + 10000] * (((b / 3 + 1) * b / 2 + 1) * b + 1);
}

// ref: https://en.wikipedia.org/wiki/Lambert_W_function, Numerical evaluation
// Halley's method
double lambert(double z, double init) {
    double w = init;
    for (int i = 0; i < 3; i++) {
        double ew = fastexp(w);
        double a = w * ew - z;
        double b = ew * (w + 1) - (w + 2) * (w * ew - z) / (2 * w + 2);
        w -= a / b;
    }
    return w;
}

namespace fastio {
    #define getchar getchar_unlocked
    #define putchar putchar_unlocked

    bool dot;

    int readInt() {
        int n, c;
        while ((c = getchar()) < '0') {
            assert(c != EOF);
        }
        n = c - '0';
        while ((c = getchar()) >= '0') {
            n = n * 10 + c - '0';
        }
        dot = c == '.';
        return n;
    }

    void printDouble(double x) {
        int a = x;
        int b = (x - a) * 1e9;
        int d[15];
        int i = 0;
        for (int j = 0; j < 9; j++) {
            d[i++] = b % 10 + '0';
            b /= 10;
        }
        d[i++] = '.';
        do {
            d[i++] = a % 10 + '0';
            a /= 10;
        } while (a > 0);
        while (i > 0) {
            putchar(d[--i]);
        }
        putchar('\n');
    }
}

double solve(int a, int b, int c, int d) {
    double lt = lg[c * 10000 + d];
    if (b == 0) {
        return fastexp(lt / a);
    }
    if (a == 0) {
        return fastexp(fastexp(lt / b));
    }
    double init = max(0.0, lt / b + lg[a] - lg[b]);
    return fastexp(lambert(fastexp(lt / b) * a / b, init) * b / a);
}

int main() {
    for (int i = 0; i <= 20000; i++) {
        ex[i] = exp((i - 10000) * 1e-3);
    }
    for (int i = 0; i < N / 2; i++) {
        lg[i] = log(i) + lte;
    }
    for (int i = N / 2; i < N + 2; i += 2) {
        double li = log(i);
        double lj = li + 1.0 / i;
        lg[i + 0] = li + lte;
        lg[i + 1] = lj + lte;
    }
    int m = fastio::readInt();
    for (int i = 0; i < m; i++) {
        int a = fastio::readInt();
        int b = fastio::readInt();
        int c = fastio::readInt();
        int d = fastio::dot ? fastio::readInt() : 0;
        fastio::printDouble(solve(a, b, c, d));
    }
}
0