Submission #536513

# Submission time Handle Problem Language Result Execution time Memory
536513 2022-03-13T13:16:41 Z fcw Hacker (BOI15_hac) C++17
100 / 100
76 ms 27708 KB
#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;

template<typename T, T (*op)(const T&, const T&)> struct monotonic_queue {
    vector<T> as, aas;
    vector<T> bs, bbs;
    void reserve(int N) {
        as.reserve(N); aas.reserve(N);
        bs.reserve(N); bbs.reserve(N);
    }
    void reduce() {
        while (!bs.empty()) {
            as.push_back(bs.back());
            aas.push_back(aas.empty() ? bs.back() : op(bs.back(), aas.back()));
            bs.pop_back(); bbs.pop_back();
        }
    }
    T get() {
        if (as.empty()) reduce();
        return (bbs.empty() ? aas.back() : op(aas.back(), bbs.back()));
    }
    bool empty() const { return (as.empty() && bs.empty()); }
    int size() const { return int(as.size()) + int(bs.size()); }
    T front() {
        if (as.empty()) reduce();
        return as.back();
    }
    void push(const T& val) {
        bs.push_back(val);
        bbs.push_back(bbs.empty() ? val : op(bbs.back(), val));
    }
    void pop() {
        if (as.empty()) reduce();
        as.pop_back();
        aas.pop_back();
    }
};

// min/max
template<typename T> T mapping_max(const T& a, const T& b) {
	return max(a, b);
}
template<typename T> using max_monotonic_queue = monotonic_queue<T, mapping_max>;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin>>n;
	vector<lint>v(n+n), pref(n+n+1);
	for(int i=0;i<n;i++) cin>>v[i], v[i+n] = v[i];
	for(int i=1;i<=n+n;i++){
		pref[i] = pref[i-1] + v[i-1];
	}
	max_monotonic_queue<lint>q;
	for(int i=1;i+n/2<=n;i++){
		q.push(pref[i+n/2-1] - pref[i-1]);
	}
	lint ans = linf;
	for(int i=0;i<n;i++){
		ans = min(ans, q.get());
		q.pop();
		q.push(pref[n+i] - pref[n+i-n/2]);
	}
	cout<<pref[n] - ans<<"\n";




	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 9 ms 4940 KB Output is correct
5 Correct 20 ms 11304 KB Output is correct
6 Correct 28 ms 13568 KB Output is correct
7 Correct 35 ms 17968 KB Output is correct
8 Correct 57 ms 27456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 9 ms 4940 KB Output is correct
36 Correct 20 ms 11304 KB Output is correct
37 Correct 28 ms 13568 KB Output is correct
38 Correct 35 ms 17968 KB Output is correct
39 Correct 57 ms 27456 KB Output is correct
40 Correct 2 ms 952 KB Output is correct
41 Correct 3 ms 1424 KB Output is correct
42 Correct 4 ms 1928 KB Output is correct
43 Correct 24 ms 11424 KB Output is correct
44 Correct 53 ms 27472 KB Output is correct
45 Correct 13 ms 5832 KB Output is correct
46 Correct 35 ms 17960 KB Output is correct
47 Correct 58 ms 27340 KB Output is correct
48 Correct 76 ms 27708 KB Output is correct
49 Correct 60 ms 26812 KB Output is correct
50 Correct 50 ms 26856 KB Output is correct