結果
| 問題 | 
                            No.2009 Drunkers' Contest
                             | 
                    
| コンテスト | |
| ユーザー | 
                             259_Momone
                         | 
                    
| 提出日時 | 2022-07-15 21:46:58 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 287 ms / 2,000 ms | 
| コード長 | 1,022 bytes | 
| コンパイル時間 | 7,265 ms | 
| コンパイル使用メモリ | 453,072 KB | 
| 最終ジャッジ日時 | 2025-01-30 07:37:55 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 54 | 
ソースコード
#include <bits/extc++.h>
#include <boost/multiprecision/cpp_int.hpp>
int main(){
    using namespace std;
    using bigint = boost::multiprecision::cpp_int;
    unsigned long N;
    cin >> N;
    vector<pair<bigint, bigint>> problems(N);
    for(auto&& [a, _] : problems)cin >> a;
    for(auto&& [_, b] : problems)cin >> b;
    reverse(begin(problems), end(problems));
    vector<pair<bigint, bigint>> stack;
    while(!empty(problems)){
        auto [a, b]{problems.back()};
        problems.pop_back();
        while(!empty(stack) && stack.back().first * b >= stack.back().second * a){
            a += stack.back().first;
            b += stack.back().second;
            stack.pop_back();
        }
        stack.emplace_back(a, b);
    }
    long double ans{};
    for(const auto& [a, b] : stack)ans += a < b ? static_cast<long double>(a) + static_cast<long double>(b) : 2 * sqrt(static_cast<long double>(a)) * sqrt(static_cast<long double>(b));
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}
            
            
            
        
            
259_Momone