Language: C++

#include <bits/stdc++.h>
#define N 30
using namespace std;
typedef long long ll;
int n,A[N];

unordered_map<ll,double> mem[N];
double calc(double a,double b){return abs(a-b)/a;}

double dfs(int idx,ll num){
  if(idx==n) return 0;
  if(mem[idx].count(num))return mem[idx][num];

  double res=1LL<<55;
  for(int i=idx;i<n;i++){
    ll t =num * ((A[i]-1)/num+1);
    res=min(res,max(calc(A[idx],t),dfs(idx+1,t)));
  }
  return mem[idx][num]=res;
}

double DP(){
  unordered_map<ll,double> dp[2];
  int f=0;  
  dp[0][1] = 0;
  for(int i=0;i<n;i++,f=!f){
    dp[!f].clear();
    for(auto it = dp[f].begin();it!=dp[f].end();it++){
      ll num = it->first;
      double cost = it->second;
      for(int j=num;;j+=num){
	if(dp[!f].count(j))dp[!f][j] = min(dp[!f][j],max(calc(A[i],j),cost));
	else dp[!f][j] = max(calc(A[i],j),cost);
	if(j>A[n-1]) break;
      }
    }
  }

  double res=1LL<<55;
  for(auto it = dp[f].begin();it!=dp[f].end();it++)res=min(res,it->second);
  return res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  printf("%.10f\n",DP());
  return 0;
}
#include <bits/stdc++.h>
#define N 30
using namespace std;
typedef long long ll;
int n,A[N];

unordered_map<ll,double> mem[N];
double calc(double a,double b){return abs(a-b)/a;}

double dfs(int idx,ll num){
  if(idx==n) return 0;
  if(mem[idx].count(num))return mem[idx][num];

  double res=1LL<<55;
  for(int i=idx;i<n;i++){
    ll t =num * ((A[i]-1)/num+1);
    res=min(res,max(calc(A[idx],t),dfs(idx+1,t)));
  }
  return mem[idx][num]=res;
}

double DP(){
  unordered_map<ll,double> dp[2];
  int f=0;  
  dp[0][1] = 0;
  for(int i=0;i<n;i++,f=!f){
    dp[!f].clear();
    for(auto it = dp[f].begin();it!=dp[f].end();it++){
      ll num = it->first;
      double cost = it->second;
      for(int j=num;;j+=num){
	if(dp[!f].count(j))dp[!f][j] = min(dp[!f][j],max(calc(A[i],j),cost));
	else dp[!f][j] = max(calc(A[i],j),cost);
	if(j>A[n-1]) break;
      }
    }
  }

  double res=1LL<<55;
  for(auto it = dp[f].begin();it!=dp[f].end();it++)res=min(res,it->second);
  return res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  printf("%.10f\n",DP());
  return 0;
}

Compiler output:
a.cc:54:5: error: redefinition of 'int n'
   54 | int n,A[N];
      |     ^
a.cc:5:5: note: 'int n' previously declared here
    5 | int n,A[N];
      |     ^
a.cc:54:7: error: redefinition of 'int A [30]'
   54 | int n,A[N];
      |       ^
a.cc:5:7: note: 'int A [30]' previously declared here
    5 | int n,A[N];
      |       ^
a.cc:56:26: error: redefinition of 'std::unordered_map<long long int, double> mem [30]'
   56 | unordered_map<ll,double> mem[N];
      |                          ^~~
a.cc:7:26: note: 'std::unordered_map<long long int, double> mem [30]' previously declared here
    7 | unordered_map<ll,double> mem[N];
      |                          ^~~
a.cc:57:8: error: redefinition of 'double calc(double, double)'
   57 | double calc(double a,double b){return abs(a-b)/a;}
      |        ^~~~
a.cc:8:8: note: 'double calc(double, double)' previously defined here
    8 | double calc(double a,double b){return abs(a-b)/a;}
      |        ^~~~
a.cc:59:8: error: redefinition of 'double dfs(int, ll)'
   59 | double dfs(int idx,ll num){
      |        ^~~
a.cc:10:8: note: 'double dfs(int, ll)' previously defined here
   10 | double dfs(int idx,ll num){
      |        ^~~
a.cc:71:8: error: redefinition of 'double DP()'
   71 | double DP(){
      |        ^~
a.cc:22:8: note: 'double DP()' previously defined here
   22 | double DP(){
      |        ^~
a.cc:93:5: error: redefinition of 'int main()'
   93 | int main(){
      |     ^~~~
a.cc:44:5: note: 'int main()' previously defined here
   44 | int main(){
      |     ^~~~