結果
| 問題 | 
                            No.2009 Drunkers' Contest
                             | 
                    
| コンテスト | |
| ユーザー | 
                             momoyuu
                         | 
                    
| 提出日時 | 2023-09-24 14:38:39 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 94 ms / 2,000 ms | 
| コード長 | 1,301 bytes | 
| コンパイル時間 | 2,947 ms | 
| コンパイル使用メモリ | 251,556 KB | 
| 実行使用メモリ | 12,196 KB | 
| 最終ジャッジ日時 | 2024-07-17 15:20:23 | 
| 合計ジャッジ時間 | 10,997 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 54 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2][310][310][310];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<double> a(n),b(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    for(int i = 0;i<n;i++) cin>>b[i];
    vector<pair<double,double>> st;
    for(int i = 0;i<n;i++){
        if(st.empty()){
            st.push_back(make_pair(a[i],b[i]));
            continue;
        }
        st.push_back(make_pair(a[i],b[i]));
        while(st.size()>=2){
            auto now = st.back();
            st.pop_back();
            auto nxt = st.back();
            st.pop_back();
            if(now.first/now.second <= nxt.first/nxt.second){
                now.first += nxt.first;
                now.second += nxt.second;
                st.push_back(now);
            }else{
                st.push_back(nxt);
                st.push_back(now);
                break;
            }
        }
    }
    double ans = 0;
    for(int i = 0;i<st.size();i++){
        auto now = st[i];
        double use = now.first / now.second;
        if(use<1) use = 0;
        else{
            use = sqrt(use) - 1;
        }
        ans += now.first /(1+use)  + now.second * (1+use);
    }
    cout<<setprecision(30)<<fixed<<ans<<endl;
}
            
            
            
        
            
momoyuu