Submission #31682

# Submission time Handle Problem Language Result Execution time Memory
31682 2017-08-31T09:27:50 Z aome Hacker (BOI15_hac) C++14
40 / 100
186 ms 13892 KB
/*input
5 
1 1 1 1 1
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 500005

int n;
int a[N];
int sum[N];
int f[N];

int getsum(int l, int r) {
	return sum[r] - sum[l - 1];
}

int ceil(int x, int y) {
	int ret = x / y;
	if (x % y) ret++;
	return ret;
}

void update(int k, int l, int r, int pos, int val) {
	if (pos < l || r < pos) return;
	if (l == r) {
		f[k] = val;
		return;
	}
	int mid = (l + r) / 2;
	update(k * 2, l, mid, pos, val); update(k * 2 + 1, mid + 1, r, pos, val);
	f[k] = max(f[k * 2], f[k * 2 + 1]);
}

int get(int k, int l, int r, int L, int R) {
	if (r < L || R < l) return 0;
	if (L <= l && r <= R) return f[k];
	int mid = (l + r) / 2;
	return max(get(k * 2, l, mid, L, R), get(k * 2 + 1, mid + 1, r, L, R));
}

// https://oj.uz/problem/view/BOI15_hac
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int last = i + n / 2 - 1;
		if (last <= n) {
			update(1, 1, n, i, getsum(i, last));
		}
		else {
			update(1, 1, n, i, getsum(i, n) + getsum(1, n / 2 - (n - i + 1)));
		}
	}

	for (int i = 1; i <= n; i++) {
		int last = i - n / 2;
		if (last < 0) last += n;
		int res = 0;
		if (last < i) {
			if (i != n)
				res = get(1, 1, n, i + 1, n);
			res = max(res, get(1, 1, n, 1, last));
		}
		else {
			res = get(1, 1, n, i + 1, last);
		}
		ans = max(ans, sum[n] - res);
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 0 ms 13892 KB Output is correct
5 Correct 0 ms 13892 KB Output is correct
6 Correct 0 ms 13892 KB Output is correct
7 Correct 0 ms 13892 KB Output is correct
8 Correct 0 ms 13892 KB Output is correct
9 Correct 0 ms 13892 KB Output is correct
10 Correct 0 ms 13892 KB Output is correct
11 Correct 0 ms 13892 KB Output is correct
12 Correct 0 ms 13892 KB Output is correct
13 Correct 0 ms 13892 KB Output is correct
14 Correct 0 ms 13892 KB Output is correct
15 Correct 0 ms 13892 KB Output is correct
16 Correct 0 ms 13892 KB Output is correct
17 Correct 0 ms 13892 KB Output is correct
18 Correct 0 ms 13892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 0 ms 13892 KB Output is correct
5 Correct 0 ms 13892 KB Output is correct
6 Correct 0 ms 13892 KB Output is correct
7 Correct 0 ms 13892 KB Output is correct
8 Correct 0 ms 13892 KB Output is correct
9 Correct 0 ms 13892 KB Output is correct
10 Correct 0 ms 13892 KB Output is correct
11 Correct 0 ms 13892 KB Output is correct
12 Correct 0 ms 13892 KB Output is correct
13 Correct 0 ms 13892 KB Output is correct
14 Correct 0 ms 13892 KB Output is correct
15 Correct 0 ms 13892 KB Output is correct
16 Correct 0 ms 13892 KB Output is correct
17 Correct 0 ms 13892 KB Output is correct
18 Correct 0 ms 13892 KB Output is correct
19 Correct 0 ms 13892 KB Output is correct
20 Correct 0 ms 13892 KB Output is correct
21 Correct 0 ms 13892 KB Output is correct
22 Correct 0 ms 13892 KB Output is correct
23 Correct 0 ms 13892 KB Output is correct
24 Correct 0 ms 13892 KB Output is correct
25 Correct 0 ms 13892 KB Output is correct
26 Correct 0 ms 13892 KB Output is correct
27 Correct 0 ms 13892 KB Output is correct
28 Correct 0 ms 13892 KB Output is correct
29 Correct 0 ms 13892 KB Output is correct
30 Correct 0 ms 13892 KB Output is correct
31 Correct 0 ms 13892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 46 ms 13892 KB Output is correct
5 Correct 119 ms 13892 KB Output is correct
6 Correct 163 ms 13892 KB Output is correct
7 Incorrect 186 ms 13892 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 0 ms 13892 KB Output is correct
5 Correct 0 ms 13892 KB Output is correct
6 Correct 0 ms 13892 KB Output is correct
7 Correct 0 ms 13892 KB Output is correct
8 Correct 0 ms 13892 KB Output is correct
9 Correct 0 ms 13892 KB Output is correct
10 Correct 0 ms 13892 KB Output is correct
11 Correct 0 ms 13892 KB Output is correct
12 Correct 0 ms 13892 KB Output is correct
13 Correct 0 ms 13892 KB Output is correct
14 Correct 0 ms 13892 KB Output is correct
15 Correct 0 ms 13892 KB Output is correct
16 Correct 0 ms 13892 KB Output is correct
17 Correct 0 ms 13892 KB Output is correct
18 Correct 0 ms 13892 KB Output is correct
19 Correct 0 ms 13892 KB Output is correct
20 Correct 0 ms 13892 KB Output is correct
21 Correct 0 ms 13892 KB Output is correct
22 Correct 0 ms 13892 KB Output is correct
23 Correct 0 ms 13892 KB Output is correct
24 Correct 0 ms 13892 KB Output is correct
25 Correct 0 ms 13892 KB Output is correct
26 Correct 0 ms 13892 KB Output is correct
27 Correct 0 ms 13892 KB Output is correct
28 Correct 0 ms 13892 KB Output is correct
29 Correct 0 ms 13892 KB Output is correct
30 Correct 0 ms 13892 KB Output is correct
31 Correct 0 ms 13892 KB Output is correct
32 Correct 0 ms 13892 KB Output is correct
33 Correct 0 ms 13892 KB Output is correct
34 Correct 0 ms 13892 KB Output is correct
35 Correct 46 ms 13892 KB Output is correct
36 Correct 119 ms 13892 KB Output is correct
37 Correct 163 ms 13892 KB Output is correct
38 Incorrect 186 ms 13892 KB Output isn't correct
39 Halted 0 ms 0 KB -