Submission #291152

# Submission time Handle Problem Language Result Execution time Memory
291152 2020-09-04T19:21:20 Z thiago4532 Bigger segments (IZhO19_segments) C++17
0 / 100
3 ms 640 KB
#include <bits/stdc++.h>
#define int int64_t

using namespace std;
const int maxn = 5e5 + 10;
typedef long long ll;
int dp[maxn], bb[maxn];
int n, v[maxn], pref[maxn];

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		pref[i] = pref[i-1] + v[i];
	}
	for (int i = 1; i <= n; i++) {
		bb[i] = max(bb[i], bb[i-1]);
		dp[i] = dp[ bb[i] ] + 1;

		int soma = pref[i] - pref[bb[i]];
		
		int ini = i+1, fim = n, meio, best;
		while (ini <= fim) {
			meio = (ini + fim) >> 1;
			if (pref[meio] + pref[ bb[i] ] >= 2*pref[i]) {
				fim = meio-1;
				best = meio;
			}else
				ini = meio+1;
		}
		bb[best] = i;
	}
	cout << dp[n] << "\n";
	return 0;
}

Compilation message

segments.cpp: In function 'int32_t main()':
segments.cpp:21:7: warning: unused variable 'soma' [-Wunused-variable]
   21 |   int soma = pref[i] - pref[bb[i]];
      |       ^~~~
segments.cpp:32:12: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |   bb[best] = i;
      |   ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Runtime error 3 ms 640 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Runtime error 3 ms 640 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Runtime error 3 ms 640 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Runtime error 3 ms 640 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Runtime error 3 ms 640 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -