Language: C++

#include <iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
​
using namespace std;
​
 
double f(double a,double p,double q,double x){
  return a*(x-p)*(x-p)+q;
} 
​
double f(double a, double p, double x){
 return sqrt(1.0 + 4.0*a*a*x*x - 8.0*a*a*p*x + 4.0*a*a*p*p);
}
double s(double a, double p, double x1, double x2){
 double N = 4.0;
 double h, p1=0.0, p2=0.0;
 h = (x2 - x1)/ N;
 for(int n = 1; n <= N/2-1; n++){
   p1 += f(a, p, x1+2.0*n*h);
 }
 for(int n = 1; n <= N/2; n++){
   p2 += f(a, p, x1+2.0*n*h-h);
 }
 p = f(a, p, x1) + 2.0*p1 + 4.0*p2 + f(a, p, x2);
 return p*h/3.0;
}
 
int main(){
  int W,H,n; cin >> W >> H >> n;
  double a[50],p[50],q[50];
  for(int i=0; i<n; i++) cin >> a[i] >> p[i] >> q[i];
 
  vector<double> X; //動的配列クラス
  X.push_back(0);//末尾に0を挿入
  X.push_back(W);//末尾にWを挿入
  for(int i=0; i<n; i++){
    // 山 i と窓枠の下辺との交点
    if(0<=p[i]-sqrt(-(q[i]/a[i])) && p[i]-sqrt(-(q[i]/a[i]))<=W) X.push_back(p[i]-sqrt(-(q[i]/a[i]))); //枠内ならx1を末尾に挿入
    if(0<=p[i]+sqrt(-(q[i]/a[i])) && p[i]+sqrt(-(q[i]/a[i]))<=W) X.push_back(p[i]+sqrt(-(q[i]/a[i]))); //枠内ならx2を末尾に挿入
 
    for(int j=0; j<i; j++){ // 山 i と山 j の交点
      double A=a[i]-a[j];
      double B=-2*a[i]*p[i]+2*a[j]*p[j];
      double C=a[i]*p[i]*p[i]+q[i]-a[j]*p[j]*p[j]-q[j];
 
      if(A!=0){ // Ax^2+Bx+C=0
        if(B*B-4*A*C>=0){
          double x;
          x=(-B-sqrt(B*B-4*A*C))/(2*A);
          if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
          x=(-B+sqrt(B*B-4*A*C))/(2*A);
          if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
        }
      }
      else if(B!=0){ // Bx+C=0
        double x=-1.0*C/B;
        if(0<=x && x<=W) X.push_back(x);//枠内なら交点を末尾に挿入
      }
    }
  }
 
  sort(X.begin(),X.end()); //昇順でソートする
 
  double ans=0;
  for(int i=0; i<(int)X.size()-1; i++){
    double x1=X[i],x2=X[i+1];
 
    int jmax=-1;
    for(int j=0; j<n; j++){
      if(f(a[j],p[j],q[j],(x1+x2)/2)>0//ｙ＝０より上
      && (jmax==-1 || f(a[jmax],p[jmax],q[jmax],(x1+x2)/2)<f(a[j],p[j],q[j],(x1+x2)/2))){//それまでで一番高い位置にある関数＜ｊ個目の関数のとき交換
        jmax=j;
      }
    }
 
    if(jmax != -1)ans+=s(a[jmax], p[jmax], x1, x2);
    
  }
 
  cout << fixed;
  cout << setprecision(9) << ans << endl;
 
  return 0;
}


Compiler output:
a.cc:6:1: error: '\U0000200b' does not name a type
    6 | ​
      |  
a.cc:8:1: error: '\U0000200b' does not name a type
    8 | ​
      |  
a.cc:13:1: error: '\U0000200b' does not name a type
   13 | ​
      |  
a.cc: In function 'double s(double, double, double, double)':
a.cc:22:10: error: 'f' was not declared in this scope
   22 |    p1 += f(a, p, x1+2.0*n*h);
      |          ^
a.cc:25:10: error: 'f' was not declared in this scope
   25 |    p2 += f(a, p, x1+2.0*n*h-h);
      |          ^
a.cc:27:6: error: 'f' was not declared in this scope
   27 |  p = f(a, p, x1) + 2.0*p1 + 4.0*p2 + f(a, p, x2);
      |      ^
a.cc: In function 'int main()':
a.cc:32:14: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   32 |   int W,H,n; cin >> W >> H >> n;
      |              ^~~
      |              std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:36:3: error: 'vector' was not declared in this scope
   36 |   vector<double> X; //動的配列クラス
      |   ^~~~~~
a.cc:36:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:36:10: error: expected primary-expression before 'double'
   36 |   vector<double> X; //動的配列クラス
      |          ^~~~~~
a.cc:37:3: error: 'X' was not declared in this scope
   37 |   X.push_back(0);//末尾に0を挿入
      |   ^
a.cc:65:3: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   65 |   sort(X.begin(),X.end()); //昇順でソートする
      |   ^~~~
      |   std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:5:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:73:31: error: 'x2' was not declared in this scope; did you mean 'x1'?
   73 |       if(f(a[j],p[j],q[j],(x1+x2)/2)>0//ｙ＝０より上
      |                               ^~
      |                               x1
a.cc:73:10: error: 'f' was not declared in this scope
   73 |       if(f(a[j],p[j],q[j],(x1+x2)/2)>0//ｙ＝０より上
      |          ^
a.cc:79:48: error: 'x2' was not declared in this scope; did you mean 'x1'?
   79 |     if(jmax != -1)ans+=s(a[jmax], p[jmax], x1, x2);
      |                                                ^~
      |                                                x1
a.cc:83:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   83 |   cout << fixed;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:83:11: error: 'fixed' was not declared in this scope; did you mean 'std::fixed'?
   83 |   cout << fixed;
      |           ^~~~~
      |           std::fixed
In file included from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/ios_base.h:1104:3: note: 'std::fixed' declared here
 1104 |   fixed(ios_base& __base)
      |   ^~~~~
a.cc:84:11: error: 'setprecision' was not declared in this scope; did you mean 'std::setprecision'?
   84 |   cout << setprecision(9) << ans << endl;
      |           ^~~~~~~~~~~~
      |           std::setprecision
In file included from a.cc:2:
/usr/include/c++/14/iomanip:202:3: note: 'std::setprecision' declared here
  202 |   setprecision(int __n)
      |   ^~~~~~~~~~~~
a.cc:84:37: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   84 |   cout << setprecision(9) << ans << endl;
      |                                     ^~~~
      |                                     std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~