結果

問題 No.456 Millions of Submits!
ユーザー pekempeypekempey
提出日時 2016-12-08 07:05:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 532 ms / 4,500 ms
コード長 3,428 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 174,076 KB
実行使用メモリ 31,156 KB
最終ジャッジ日時 2023-09-05 12:27:35
合計ジャッジ時間 9,713 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,400 KB
testcase_01 AC 7 ms
7,612 KB
testcase_02 AC 7 ms
7,624 KB
testcase_03 AC 8 ms
7,260 KB
testcase_04 AC 8 ms
7,316 KB
testcase_05 AC 11 ms
7,624 KB
testcase_06 AC 11 ms
7,224 KB
testcase_07 AC 14 ms
7,512 KB
testcase_08 AC 14 ms
7,248 KB
testcase_09 AC 19 ms
7,908 KB
testcase_10 AC 19 ms
8,188 KB
testcase_11 AC 68 ms
10,876 KB
testcase_12 AC 532 ms
31,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// #define getchar getchar_unlocked
// #define putchar putchar_unlocked

bool dot;
const int H = 17;
const int N = 1 << H;
const double L = 0;
const double R = log(10);
const double LL = -1e100;
const double RR = log(R);
const double dx = R / (1 << H);
const double logDX = log(R) - H * log(2);
const double log00001 = -4 * log(10);

double lg[N + 1];
bool prime[N + 1];
vector<int> bin[100001];
vector<int> gr[11][11];

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

void out(double x) {
    static char buf[20];
    sprintf(buf, "%.9f", x);
    for (int i = 0; buf[i] != '\0'; i++) {
        putchar(buf[i]);
    }
    putchar('\n');
}

void sieve() {
    lg[0] = log(0);
    for (int i = 2; i <= N; i++) {
        if (!prime[i]) {
            double g = log(i);
            for (long long j = i; j < N; j *= i) {
                for (long long k = j; k < N; k += j) {
                    prime[k] = true;
                    lg[k] += g;
                }
            }
        }
    }
    for (int i = 0; i <= N; i++) {
        lg[i] += logDX;
    }
}

double elapsed() {
    static clock_t curr;
    clock_t prev = curr;
    curr = clock();
    return (double)(curr - prev) / CLOCKS_PER_SEC;
}

int main() {
    elapsed();
    int m = in();
    sieve();
    vector<char> a(m), b(m), d(m);
    vector<int> c(m);
    vector<int> cnt(100001);
    vector<vector<int>> cnt1(11, vector<int>(11));
    for (int i = 0; i < m; i++) {
        a[i] = in();
        b[i] = in();
        d[i] = in();
        c[i] = dot ? in() : 0;
        c[i] = d[i] * 10000 + c[i];
        cnt[c[i]]++;
        cnt1[a[i]][b[i]]++;
    }
    for (int i = 0; i <= 100000; i++) {
        bin[i].reserve(cnt[i]);
    }
    for (int i = 0; i <= 10; i++) {
        for (int j = 0; j <= 10; j++) {
            gr[i][j].reserve(cnt1[i][j]);
        }
    }
    for (int i = 0; i < m; i++) {
        bin[c[i]].push_back(i);
    }
    for (int i = 0; i <= 100000; i++) {
        for (int j : bin[i]) {
            gr[a[j]][b[j]].push_back(j);
        }
    }
    vector<double> ans(m);
    for (int a = 0; a <= 10; a++) {
        for (int b = 0; b <= 10; b++) {
            if (gr[a][b].empty()) {
                continue;
            }
            if (b == 0) {
                for (int i : gr[a][b]) {
                    const double logT = lg[c[i]] - logDX + log00001;
                    ans[i] = exp(logT / a);
                }
                continue;
            }
            if (a == 0) {
                for (int i : gr[a][b]) {
                    const double logT = lg[c[i]] - logDX + log00001;
                    ans[i] = exp(exp(logT / b));
                }
                continue;
            }
            int l = 1;
            for (int i : gr[a][b]) {
                const double logT = lg[c[i]] - logDX + log00001;
                while (l < N && a * l * dx + b * lg[l] < logT) {
                    l++;
                }
                int ll = l - 1;
                double s = (lg[ll + 1] - lg[ll]) / dx;
                ans[i] = exp((logT + s * b * ll * dx - lg[ll] * b) / (s * b + a));
            }
        }
    }
    for (int i = 0; i < m; i++) {
        out(ans[i]);
    }
}
0