이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Be name khode //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int maxn5 = 2e3 + 5;
int a[maxn5];
struct kasr{
__int128 up, dw;
int l, r;
kasr(){
}
kasr(ll u, ll d){
up = u;
dw = d;
}
} av[maxn5 * maxn5], keep[maxn5][maxn5];
bool operator <(kasr a, kasr b){
return a.up * b.dw < a.dw * b.up;
}
bool operator <=(kasr a, kasr b){
return a.up * b.dw <= a.dw * b.up;
}
ld operator -(kasr a, kasr b){
ld ax = a.up, ay = a.dw, bx = b.up, by = b.dw;
return ax / ay - bx / by;
}
void out(kasr a){
cout << ld(a.up) << ' ' << ld(a.dw) << ' ' << ld(a.up) / ld(a.dw) << endl;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
ll all = 0;
int pt = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
all += a[i];
ll sum = 0;
for(int j = i; j >= 0; j--){
sum += a[j];
av[pt].up = sum;
av[pt].dw = (i - j + 1);
av[pt].l = j;
av[pt].r = i;
keep[i][j] = av[pt];
pt++;
}
}
sort(av, av + pt);
kasr lim(all, n);
kasr mnr = lim;
ld ans = 1e18;
int cnt = 0;
for(int i = 0; i < pt && av[i] <= lim; i++){
ans = min(ans, mnr - av[i]);
//cout << i << ' ' << av[i].l << ' ' << av[i].r << ' ' << ans << endl;
//out(mnr);
//out(av[i]);
int v = av[i].r;
if(v + 1 < n && mnr < keep[v + 1][av[i].l + 1]){
mnr = keep[v + 1][av[i].l + 1];
cnt++;
}
}
assert(cnt <= 10 * n);
cout << setprecision(15) << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |