Submission #1127009

#TimeUsernameProblemLanguageResultExecution timeMemory
1127009gawr_guraSeesaw (JOI22_seesaw)C++20
1 / 100
2094 ms328 KiB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define pb push_back

using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const double base = 1.000000000;

int n, a[M];
double kq = 1e15;
int x[M];
void ktra()
{
  double sum = 0;
  for(int i = 1;i <= n; i++) sum += a[i];
  int l = 1, r = n;
  double u = sum/n, v = sum/n;
  for(int i = 1;i <= n - 1; i++) {
    if(x[i] == 0) {
      sum -= a[l];
      l++;
      double val = base * sum/(n - i);
      //cout << sum << " " << (n - i) << " "  << val << "\n";
      u = min(u, val);
      v = max(v, val);
    }
    else {
      sum -= a[r];
      r--;
      double val = base * sum/(n - i);
      //cout << sum << " " << (n - i) << " " << val << "\n" ;
      u = min(u, val);
      v = max(v, val);

    }
  }
  //cout << u << " " << v << "\n";
  //cout << endl;
  kq = min(kq, base * v - u);
}


void duyet(int i)
{
  if(i == n) ktra();
  else
  {
    for(int j = 0;j <= 1; j++) {
      x[i] = j;
      duyet(i + 1);
    }
  }
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  if(fopen("1.inp","r")) {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }

  #define task ""
  if(fopen(task".inp","r")) {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

  cin >> n ;
  for(int i = 1;i <= n; i++) cin >> a[i];
  duyet(1);
  cout << fixed << setprecision(9) << kq  ;


}


Compilation message (stderr)

seesaw.cpp: In function 'int32_t main()':
seesaw.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
seesaw.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
seesaw.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
seesaw.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...