結果

問題 No.2009 Drunkers' Contest
ユーザー milanis48663220milanis48663220
提出日時 2022-07-15 23:01:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,665 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 125,388 KB
実行使用メモリ 13,508 KB
最終ジャッジ日時 2023-09-10 04:29:58
合計ジャッジ時間 6,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 59 ms
6,284 KB
testcase_25 AC 59 ms
6,200 KB
testcase_26 AC 59 ms
6,216 KB
testcase_27 AC 59 ms
6,208 KB
testcase_28 AC 59 ms
6,148 KB
testcase_29 AC 59 ms
6,200 KB
testcase_30 AC 58 ms
6,208 KB
testcase_31 AC 58 ms
6,280 KB
testcase_32 AC 59 ms
6,160 KB
testcase_33 AC 58 ms
6,152 KB
testcase_34 AC 53 ms
6,156 KB
testcase_35 AC 53 ms
6,152 KB
testcase_36 AC 53 ms
6,152 KB
testcase_37 AC 53 ms
6,228 KB
testcase_38 AC 53 ms
6,172 KB
testcase_39 AC 54 ms
6,152 KB
testcase_40 AC 53 ms
6,196 KB
testcase_41 AC 53 ms
6,352 KB
testcase_42 AC 53 ms
6,164 KB
testcase_43 AC 53 ms
6,424 KB
testcase_44 AC 63 ms
12,800 KB
testcase_45 AC 64 ms
13,388 KB
testcase_46 AC 49 ms
12,732 KB
testcase_47 AC 42 ms
13,348 KB
testcase_48 AC 42 ms
12,984 KB
testcase_49 AC 41 ms
13,472 KB
testcase_50 AC 42 ms
13,508 KB
testcase_51 AC 42 ms
12,608 KB
testcase_52 AC 40 ms
9,564 KB
testcase_53 AC 47 ms
9,568 KB
testcase_54 AC 46 ms
9,988 KB
testcase_55 AC 44 ms
6,732 KB
testcase_56 AC 43 ms
6,816 KB
testcase_57 AC 45 ms
9,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<ll, ll>;
using T = tuple<ll, ll, double>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    auto f = [&](ll a, ll b){
        double x = sqrt((double)a/(double)b);
        return max(x, 1.0);
    };
    vector<T> vt;
    function<void()> optimize = [&](){
        if(vt.size() <= 1) return;
        auto [a1, b1, x1] = vt.back();
        auto [a0, b0, x0] = vt[vt.size()-2];
        if(x1 > x0){
            vt.pop_back(); vt.pop_back();
            vt.push_back(T(a0+a1, b0+b1, f(a0+a1, b0+b1)));
            optimize();
        }else{
            double t0 = (double)a0/x0 + (double)b0*x0;
            double t1 = (double)a1/x1 + (double)b1*x1;

            double aa = a0+a1, bb = b0+b1, xx = f(aa, bb);
            double tt = (double)aa/xx + (double)bb*xx;
            if(tt < t0+t1){
                vt.pop_back(); vt.pop_back();
                vt.push_back(T(aa, bb, xx));
                optimize();
            }
        }
    };
    for(int i = n-1; i >= 0; i--){
        ll aa = a[i], bb = b[i];
        double xx = f(aa, bb);
        vt.push_back(T(aa, bb, xx));
        optimize();
    }
    double ans = 0.0;
    for(auto [a, b, x]: vt){
        // cout << a << ' ' << b << ' ' << x << endl;
        ans += (double)a/x + (double)b*x;
    }
    cout << ans << endl;
}
0