#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
struct DSU{
int path[4004000], chk[4004000], n;
vector<int> buf;
void init(int _n){
n = _n;
for (int i=0;i<n*n;i++) path[i] = i, chk[i] = 0;
}
int find(int s){
if (s==path[s]) return s;
return path[s] = find(path[s]);
}
void merge(int s, int v){
if (!chk[s] || !chk[v]) return;
s = find(s), v = find(v);
if (s==v) return;
path[s] = v;
}
void on(int x, int y){
int pos = (x-1)*n + y-1;
if (x==y) pos = 0;
chk[pos] = 1;
buf.push_back(pos);
for (int k=0;k<4;k++){
int nx = x + dx[k], ny = y + dy[k];
if (nx<=0 || nx>n || ny<=0 || ny>n || nx>ny) continue;
int np = (nx-1)*n + ny-1;
merge(pos, np);
}
}
void off(){for (auto &x:buf){path[x] = x; chk[x] = 0;} buf.clear();}
bool ok(){return find(0) == find(n-1) && chk[0] && chk[n-1];}
}dsu;
struct Frac{
ll a, b;
Frac(){}
Frac(ll _a, ll _b): a(_a), b(_b) {}
long double ch(){return (long double) a / b;}
bool operator < (const Frac &F) const{
return (__int128)a * F.b < (__int128)b * F.a;
}
}val[2020][2020];
int n, a[2020];
Frac dp[2020][2020];
long double solve(int sx, int sy){
for (int i=1;i<=n;i++) fill(dp[i]+1, dp[i]+n+1, Frac((ll)1e18, 1));
dp[sx][sy] = val[sx][sy];
Frac ret1 = dp[1][n], ret2 = dp[sx][sx];
for (int d=sy-sx+1;d<=n-1;d++){
for (int i=1;i<=n-d;i++){
int j = i+d;
if (val[i][j] < val[sx][sy]) continue;
dp[i][j] = max(val[i][j], min(dp[i+1][j], dp[i][j-1]));
}
}
ret1 = dp[1][n];
for (int d=sy-sx-1;d>=0;d--){
for (int i=1;i<=n-d;i++){
int j = i+d;
if (val[i][j] < val[sx][sy]) continue;
dp[i][j] = max(val[i][j], min(dp[i-1][j], dp[i][j+1]));
if (i==j) ret2 = min(ret2, dp[i][j]);
}
}
auto ret = max(ret1, ret2);
return ret.ch() - val[sx][sy].ch();
}
int main(){
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", a+i);
for (int i=1;i<=n;i++){
val[i][i] = Frac(a[i], 1);
for (int j=i+1;j<=n;j++){
val[i][j].a = val[i][j-1].a + a[j];
val[i][j].b = j-i+1;
//printf("%Lf ", val[i][j].ch());
}
//printf("\n");
}
long double ans = 1e18;
for (int i=1;i<=n;i++){
for (int j=i;j<=n;j++) ans = min(ans, solve(i, j));
}
printf("%.15Lf\n", ans);
return 0;
}
Compilation message
seesaw.cpp: In function 'int main()':
seesaw.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
seesaw.cpp:88:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | for (int i=1;i<=n;i++) scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
137 ms |
1364 KB |
Output is correct |
5 |
Correct |
138 ms |
1364 KB |
Output is correct |
6 |
Correct |
139 ms |
1364 KB |
Output is correct |
7 |
Correct |
141 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
137 ms |
1364 KB |
Output is correct |
5 |
Correct |
138 ms |
1364 KB |
Output is correct |
6 |
Correct |
139 ms |
1364 KB |
Output is correct |
7 |
Correct |
141 ms |
1364 KB |
Output is correct |
8 |
Execution timed out |
2084 ms |
102476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
137 ms |
1364 KB |
Output is correct |
5 |
Correct |
138 ms |
1364 KB |
Output is correct |
6 |
Correct |
139 ms |
1364 KB |
Output is correct |
7 |
Correct |
141 ms |
1364 KB |
Output is correct |
8 |
Execution timed out |
2084 ms |
102476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |