Advertisement
Abrar_Al_Samit

Cow Dating (USACO '19 Plat) (Guessed N AC)

Aug 4th, 2022
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int C = 1000000;
  5. const double err = 1e-15;
  6. void PlayGround() {
  7.   int n;
  8.   cin>>n;
  9.   double p[n];
  10.   for(int i=0; i<n; ++i) {
  11.     cin>>p[i];
  12.     p[i] /= C;
  13.   }
  14.  
  15.   double ans = 0;
  16.   double cur = 0;
  17.   double invProd = 1;
  18.   int pointer = 0;
  19.   for(int i=0; i<n; ++i) {
  20.     while(pointer<n) {
  21.       double new_cur = cur * (1-p[pointer]) + p[pointer] * invProd;
  22.       if(new_cur>cur) {
  23.         cur = new_cur;
  24.         invProd *= (1-p[pointer]);
  25.         ++pointer;
  26.       } else break;
  27.     }
  28.     ans = max(ans, cur);
  29.     cur -= p[i] * (invProd / (1-p[i]));
  30.     cur /= 1-p[i];
  31.     invProd /= 1-p[i];
  32.   }
  33.   ans += err;
  34.   cout<<(int)(ans*C)<<'\n';
  35. }
  36. int main() {
  37.   freopen("cowdate.in", "r", stdin);
  38.   freopen("cowdate.out", "w", stdout);
  39.   PlayGround();
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement