답안 #801893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801893 2023-08-02T08:17:45 Z Sohsoh84 Giraffes (JOI22_giraffes) C++17
0 / 100
1 ms 212 KB
// Wounds should become scars but I'm cracked instead U+1FAE0
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;

int A[MAXN], n;

inline ld calc(int l, int r) {
	ll s = 0;
	for (int i = l; i <= r; i++)
		s += A[i];

	return ld(s) / (r - l + 1);
}

inline ld solve(ld max_r) {
	int l = 1, r = n;
	ld tl = calc(l, r), tr = calc(l, r);
	while (l < r) {
		ld tll = min(tl, calc(l + 1, r)), tlr = max(tr, calc(l + 1, r));
		if (tlr <= max_r) l++;
		else r--;

		tl = min(tl, calc(l, r));
		tr = max(tr, calc(l, r));
	}

	return tr - tl;
}

inline ld solve2(ld min_l) {
	int l = 1, r = n;
	ld tl = calc(l, r), tr = calc(l, r);
	while (l < r) {
		ld trl = min(tl, calc(l, r - 1)), trr = max(tr, calc(l, r - 1));
		if (trl >= min_l) r--;
		else l++;

		tl = min(tl, calc(l, r));
		tr = max(tr, calc(l, r));
	}

	return tr - tl;	
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> A[i];
	
	ld ans = A[n] - A[1];
	ans = min(ans, solve(calc(1, n)));
//	ans = min(ans, solve2(calc(1, n)));

	cout << setprecision(10) << fixed << ans << endl;
	return 0;
}

Compilation message

giraffes.cpp: In function 'ld solve(ld)':
giraffes.cpp:33:6: warning: unused variable 'tll' [-Wunused-variable]
   33 |   ld tll = min(tl, calc(l + 1, r)), tlr = max(tr, calc(l + 1, r));
      |      ^~~
giraffes.cpp: In function 'ld solve2(ld)':
giraffes.cpp:48:37: warning: unused variable 'trr' [-Wunused-variable]
   48 |   ld trl = min(tl, calc(l, r - 1)), trr = max(tr, calc(l, r - 1));
      |                                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -