Submission #998766

# Submission time Handle Problem Language Result Execution time Memory
998766 2024-06-14T16:32:16 Z ZeroCool Seesaw (JOI22_seesaw) C++14
100 / 100
73 ms 16328 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ar array
#define ld long double

const int N = 2e5 + 20;
const int MOD = 1e9 + 7;
const int LOG = 30;

int A[N];

ld get(int l,int r){
	return (ld)(A[r] - A[l-1]) / (r - l + 1);
}

signed main(){ios::sync_with_stdio(false);cin.tie(0);	
	int n;
	cin>>n;
	for(int i =1;i<=n;i++){
		cin>>A[i];
		A[i] += A[i-1];
	}
	
	int l = 1;
	int r = n;
	vector<ar<ld, 3> > v;
	while(l != r){
		if(get(l, r - 1) >= get(1, n)){
			r--;
			
		}else l++;
		v.push_back({get(l, r), l, r});
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ld ans = 1e9;
	ld mn = get(1, n);
	for(auto [cen, l, r]: v){
		ans = min(ans, cen - mn);
		mn = min(mn, get(l -1, r- 1));	
	}
	ans = min(ans, get(1, n) - mn);
	cout<<setprecision(12)<<fixed<<ans<<'\n';
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:35:27: warning: narrowing conversion of 'l' from 'long long int' to 'long double' [-Wnarrowing]
   35 |   v.push_back({get(l, r), l, r});
      |                           ^
seesaw.cpp:35:30: warning: narrowing conversion of 'r' from 'long long int' to 'long double' [-Wnarrowing]
   35 |   v.push_back({get(l, r), l, r});
      |                              ^
seesaw.cpp:41:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |  for(auto [cen, l, r]: v){
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 71 ms 16324 KB Output is correct
13 Correct 68 ms 16172 KB Output is correct
14 Correct 73 ms 16328 KB Output is correct
15 Correct 69 ms 16320 KB Output is correct
16 Correct 70 ms 16316 KB Output is correct