Submission #612296

# Submission time Handle Problem Language Result Execution time Memory
612296 2022-07-29T12:44:50 Z cheissmart Seesaw (JOI22_seesaw) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
typedef long double db;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, N = 2e5 + 6;
const ll oo = 1e18;

int a[N];
ll p[N];

signed main()
{
	IO_OP;

	cout << fixed << setprecision(12);

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		p[i] = p[i - 1] + a[i];
	}
	V<db> aux;
	for(int i = 1; i <= n; i++) {
		for(int j = i; j <= n; j++) {
			aux.PB(db(p[j] - p[i - 1]) / (j - i + 1));
		}
	}
	sort(ALL(aux));
	aux.resize(unique(ALL(aux)) - aux.begin());

	auto go = [&] (double mn) {
		V<V<db>> dp(n + 1, V<db>(n + 1, oo));
		for(int len = 1; len <= n; len++) {
			for(int i = 1; i + len - 1 <= n; i++) {
				int j = i + len - 1;
				db tt = db(p[j] - p[i - 1]) / (j - i + 1);
				if(tt >= mn) {
					if(i == j)
						dp[i][j] = tt;
					else {
						dp[i][j] = max(min(dp[i][j - 1], dp[i + 1][j]), tt);
					}
				}
			}
		}
		return dp[1][n] - mn;
	};
	int pos = find(ALL(aux), db(p[n]) / n) - aux.begin();
	int lb = 0, rb = pos - 1;
	while(lb <= rb) {
		int mb = (lb + rb) / 2;
		if(go(aux[mb]) < go(aux[mb + 1])) rb = mb - 1;
		else lb = mb + 1;
	}
	cout<< go(aux[lb]) << '\n';

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -