結果
| 問題 | 
                            No.2009 Drunkers' Contest
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-04-26 03:11:01 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 201 ms / 2,000 ms | 
| コード長 | 642 bytes | 
| コンパイル時間 | 2,130 ms | 
| コンパイル使用メモリ | 198,684 KB | 
| 最終ジャッジ日時 | 2025-01-28 21:54:25 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 54 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long long >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<long long,long long>>ret;
  for(int i=n-1;i>=0;i--){
    long long now_a=a[i],now_b=b[i];
    while(ret.size()&&!((double)ret.back().first/ret.back().second>=(double)now_a/now_b)){
      now_a+=ret.back().first;
      now_b+=ret.back().second;
      ret.pop_back();
    }
    ret.push_back({now_a,now_b});
  }
  double ans=0;
  for(auto&[x,y]:ret){
    if(x>=y)ans+=2.0*sqrt(x)*sqrt(y);
    else ans+=x+y;
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
}