Submission #1088813

# Submission time Handle Problem Language Result Execution time Memory
1088813 2024-09-15T07:01:27 Z xnqs Bigger segments (IZhO19_segments) C++17
0 / 100
0 ms 460 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

int x;
int arr[500005];
int64_t pfx[500005];
std::vector<int64_t> stk;

int solve(int start) {
	int64_t sum = 0;
	for (int i = start; i <= x; i++) {
		sum += arr[i];
		if (stk.back()<=sum) {
			stk.emplace_back(sum);
			sum = 0;
		}
	}

	if (sum) {
		stk.emplace_back(sum);
	}

	if (stk.size()>=2&&stk[stk.size()-2]>stk[stk.size()-2]) {
		stk[stk.size()-2] += stk[stk.size()-1];
		stk.pop_back();
	}

	return static_cast<int>(stk.size());
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	std::cin >> x;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
		pfx[i] = pfx[i-1] + arr[i];
	}

	int64_t first_sum = 0;
	int ans = 0;
	for (int start = 1; start <= x; start++) {
		first_sum += arr[start];
		stk.emplace_back(first_sum);
		ans = std::max(ans, solve(start+1));
		stk.clear();
	}

	std::cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -