답안 #1063592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063592 2024-08-17T21:02:52 Z TimDee Seesaw (JOI22_seesaw) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0; i<n; ++i)
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

const int N=1005;
double med[N][N];

void solve() {
	
	int n; cin>>n;
	vii(a,n);

	vector<pair<double,int>> v;
	forn(i,n) {
		int s=0;
		for(int j=i; j<n; ++j) {
			s+=a[j];
			double z = 1.0*s/(j-i+1);
			v.pb({z,j-i});
		}
	}
	sort(all(v));
	vector<int> cnt(n);
	int tot=0;
	int r=0;
	double ans=a[n-1]-a[0];
	forn(i,v.size()) {
		while (r<v.size() && tot<n) {
			tot+=!cnt[v[r].s];
			++cnt[v[r].s];
			++r;
		}
		if (tot==n) ans=min(ans,v[r-1].f - v[i].f);
		--cnt[v[i].s];
		tot-=!cnt[v[i].s];
	}
	cout<<fixed<<setprecision(10)<<ans<<'\n';

}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}

Compilation message

seesaw.cpp: In function 'void solve()':
seesaw.cpp:4:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0; i<n; ++i)
......
   33 |  forn(i,v.size()) {
      |       ~~~~~~~~~~                 
seesaw.cpp:33:2: note: in expansion of macro 'forn'
   33 |  forn(i,v.size()) {
      |  ^~~~
seesaw.cpp:34:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   while (r<v.size() && tot<n) {
      |          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -