結果

問題 No.456 Millions of Submits!
ユーザー kimiyukikimiyuki
提出日時 2016-12-08 18:15:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,775 ms / 4,500 ms
コード長 1,956 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 63,020 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2023-09-05 20:46:21
合計ジャッジ時間 5,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 7 ms
4,384 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 25 ms
4,380 KB
testcase_10 AC 25 ms
4,376 KB
testcase_11 AC 187 ms
5,600 KB
testcase_12 AC 1,775 ms
32,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
const double eps = 1e-10;
double newton(int a, int b, double t, double n) {
    assert (a >= 1 and b >= 1);
    auto f = [&](double n) {
        return pow(n, a) * pow(log(n), b);
    };
    auto f1 = [&](double n) {
        return a * pow(n, a-1) * pow(log(n), b) + pow(n, a) * b * 1/n * pow(log(n), b-1);
    };
    for (double delta = INFINITY; delta > eps; ) {
        delta = (f(n) - t) / f1(n);
        n -= delta;
    }
    return n;
}
int main() {
    // input
    int m; scanf("%d", &m);
    vector<int> as(m), bs(m);
    vector<double> ts(m);
    repeat (i,m) scanf("%d%d%lf", &as[i], &bs[i], &ts[i]);
    // solve
    array<array<vector<int>, 10+1>, 10+1> xs = {};
    repeat (i,m) xs[as[i]][bs[i]].push_back(i);
    vector<double> n(m);
    repeat (a,10+1) {
        repeat (b,10+1) {
            if (a == 0) {
                for (int x : xs[a][b]) {
                    n[x] = exp(pow(ts[x], 1.0/b));
                }
            } else if (b == 0) {
                for (int x : xs[a][b]) {
                    n[x] = pow(ts[x], 1.0/a);
                }
            } else {
                whole(sort, xs[a][b], [&](int x, int y) {
                    return ts[x] < ts[y];
                });
                double prev = 22027; // exp(10)
                repeat_reverse (i, int(xs[a][b].size())) {
                    int x = xs[a][b][i];
                    double t = ts[x];
                    prev = n[x] = newton(a, b, t, prev);
                }
            }
        }
    }
    // output
    repeat (i,m) {
        printf("%.12lf\n", n[i]);
    }
    return 0;
}
0