답안 #752761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
752761 2023-06-03T19:16:34 Z IBory Seesaw (JOI22_seesaw) C++14
0 / 100
1 ms 340 KB
#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;
	P.emplace_back(S[N] / (double)N, N);
	int SL = 1, SR = N;
	for (int d = N - 1; d > 0; --d) {
		if ((SR - SL) == d) {
			P.emplace_back((S[SR] - S[SL]) / (double)(d), d);
			P.emplace_back((S[SR - 1] - S[SL - 1]) / (double)(d), d);
		}
		else {
			P.emplace_back((S[SR] - S[SL + 1]) / (double)(d), d);
			P.emplace_back((S[SR - 1] - S[SL]) / (double)(d), d);
			P.emplace_back((S[SR - 2] - S[SL - 1]) / (double)(d), d);
			SR--; SL++;
		}
	}
	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

seesaw.cpp: In function 'int main()':
seesaw.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int L = 0; L < P.size(); ++L) {
      |                  ~~^~~~~~~~~~
seesaw.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   while (R + 1 < P.size() && cnt != N - 1) {
      |          ~~~~~~^~~~~~~~~~
seesaw.cpp:17:6: warning: unused variable 'g' [-Wunused-variable]
   17 |  int g = N / 2;
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -