# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752641 | IBory | Seesaw (JOI22_seesaw) | C++14 | 711 ms | 1048576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAX = 200007;
ll S[MAX], on[MAX];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N;
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> S[i];
S[i] += S[i - 1];
}
int g = N / 2;
vector<pair<double, int>> P;
for (int d = 1; d <= N; ++d) {
//if ((N - d) % 2 == 0) {
// P.emplace_back((S[N - g] - S[N - g - d]) / (double)d, d);
//}
//else {
// P.emplace_back((S[N - g] - S[N - g - d]) / (double)d, d);
// P.emplace_back((S[N - g + 1] - S[N - g + 1 - d]) / (double)d, d);
// g--;
//}
for (int i = d; i <= N; ++i) {
P.emplace_back((S[i] - S[i - d]) / (double)d, d);
}
}
sort(P.begin(), P.end());
double ans = 1e18;
int cnt = 0, R = 0;
on[P[0].second] = 1;
for (int L = 0; L < P.size(); ++L) {
while (R + 1 < P.size() && cnt != N - 1) {
int t = P[++R].second;
if (t != 1 && on[t - 1] && !on[t]) cnt++;
if (t != N && on[t + 1] && !on[t]) cnt++;
on[t]++;
}
if (cnt == N - 1) ans = min(ans, P[R].first - P[L].first);
int t = P[L].second;
on[t]--;
if (t != 1 && on[t - 1] && !on[t]) cnt--;
if (t != N && on[t + 1] && !on[t]) cnt--;
}
cout.precision(12);
cout << fixed << ans;
return 0;
}
Compilation message (stderr)
# | 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... |