Submission #1291963

#TimeUsernameProblemLanguageResultExecution timeMemory
1291963MrDogMeatSeesaw (JOI22_seesaw)C++20
1 / 100
13 ms572 KiB
#include<bits/stdc++.h>

using namespace std;

///vector
#define SZ(x) (int)x.size()

using ld = long double;

const int MAXN = 2e5;
const int INF32 = 1e9;

template <class X, class Y> bool minimize(X &x, const Y &y) { if(x > y) { x = y; return 1; } return 0; }
template <class X, class Y> bool maximize(X &x, const Y &y) { if(x < y) { x = y; return 1; } return 0; }

///input
int N;
int A[MAXN+5];

namespace sub1 {
    ld Ans = INF32;

    void brute_force(int l, int r, ld sum, ld MinPos, ld MaxPos) {
        if(r == l) {
            minimize(Ans, MaxPos - MinPos);
            return;
        }

        int len = r - l;
        ld tmp_sum = sum - A[l], bary = tmp_sum/len;
        brute_force(l + 1, r, tmp_sum, min(MinPos, bary), max(MaxPos, bary));
        tmp_sum = sum - A[r], bary = tmp_sum/len;
        brute_force(l, r - 1, tmp_sum, min(MinPos, bary), max(MaxPos, bary));
    }

    void solution() {
        ld sum = 0;
        for(int i = 1; i <= N; i++) {
            sum += A[i];
        }
        brute_force(1, N, sum, sum/N, sum/N);
        cout << Ans;
    }

    bool check() {
        return (N <= 20);
    }
}

void solution() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    cout << setprecision(10) << fixed;
    if(sub1::check()) return sub1::solution();
}

#define FILE "task"
main() {
    if(fopen(FILE".in","r")) {
        freopen(FILE".in","r",stdin);
        freopen(FILE".out","w",stdout);
    }
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);

    solution();

    cerr << "\n" << clock() << " ms";
    return 0;
}

Compilation message (stderr)

seesaw.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main() {
      | ^~~~
seesaw.cpp: In function 'int main()':
seesaw.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(FILE".in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
seesaw.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(FILE".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...