Submission #612334

# Submission time Handle Problem Language Result Execution time Memory
612334 2022-07-29T13:10:13 Z wiwiho Seesaw (JOI22_seesaw) C++14
34 / 100
2000 ms 31772 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll ifloor(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a < 0) return (a - b + 1) / b;
    else return a / b;
}

ll iceil(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a > 0) return (a + b - 1) / b;
    else return a / b;
}

int main(){
    StarBurstStream

    int n;
    cin >> n;

    vector<ll> a(n + 1), s(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i], s[i] = s[i - 1] + a[i];

    auto getcen = [&](int l, int r){
        return mp(s[r] - s[l - 1], r - l + 1);
    };
    auto comp = [&](pll xc, pll yc){
        return (__int128)xc.F * yc.S < (__int128)yc.F * xc.S;
    };
    
    vector<pii> tmp;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++) tmp.eb(mp(i, j));
    }
    sort(iter(tmp), [&](pii x, pii y){
        pll xc = getcen(x.F, x.S);
        pll yc = getcen(y.F, y.S);
        return comp(xc, yc);
    });

    vector<vector<int>> rk(n + 1, vector<int>(n + 1));
    for(int i = 0; i < (int)tmp.size(); i++){
        rk[tmp[i].F][tmp[i].S] = i;
    }

    auto getpos = [&](int t){
        int l, r;
        tie(l, r) = tmp[t];
        pll owo = getcen(l, r);
        return (ld)owo.F / owo.S;
    };

    ld ans = 1e87;
    for(int i = 0; i <= rk[1][n]; i++){
        int l = 1, r = n;
        int mx = rk[l][r];
        while(l < r){
            if(i <= rk[l][r - 1]) r--;
            else l++;
            mx = max(mx, rk[l][r]);
        }
        ld tans = getpos(mx) - getpos(i);
        ans = min(ans, tans);
    }

    cout << fixed << setprecision(20) << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 320 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 320 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Execution timed out 2041 ms 31772 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 320 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Execution timed out 2041 ms 31772 KB Time limit exceeded
9 Halted 0 ms 0 KB -