Submission #31572

# Submission time Handle Problem Language Result Execution time Memory
31572 2017-08-30T01:46:01 Z user202729 Hacker (BOI15_hac) C++14
100 / 100
173 ms 11948 KB
// https://oj.uz/problem/view/BOI15_hac

#include <iostream>
#include <vector>
#include <deque>

typedef std::pair<int,int> ii;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> value (n), segvalue (n);
    for (int& i : value) std::cin >> i;
    value.insert(value.end(), value.begin(), value.end());
//    for (int& i : value) std::cout << i << ' ';
    for (int i = 1; i < 2 * n; ++i) value[i] += value[i-1]; // conv to sum table
    int seglen = (n+1)/2;
    for (int i = 0; i < n; ++i) segvalue[i] = value[i+seglen] - value[i];
    value.clear(); // no longer need value
    segvalue.insert(segvalue.end(), segvalue.begin(), segvalue.end());
    std::deque<ii> candidatepairs; // need to calculate min of windows, then pick the max of min's
    // ii : index -> value (in segvalue)
    for (int i = 0; i < seglen-1; ++i) {
        while ((!candidatepairs.empty()) && candidatepairs.back().second >= segvalue[i])
            candidatepairs.pop_back();
        candidatepairs.emplace_back(i, segvalue[i]);
    }
    int result = -1; // need to get max
    for (int i = 0; i < n; ++i) {
        // segment [i .. i+seglen)
        // insert i+seglen-1
        int j = i+seglen-1;
        while ((!candidatepairs.empty()) && candidatepairs.back().second >= segvalue[j])
            candidatepairs.pop_back();
        candidatepairs.emplace_back(j, segvalue[j]);
        // delete anything < i
        while ((!candidatepairs.empty()) && candidatepairs.front().first < i) candidatepairs.pop_front();
        // and get the min
        result = std::max(result, candidatepairs.front().second);
    }
    std::cout << result << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 0 ms 2020 KB Output is correct
9 Correct 0 ms 2020 KB Output is correct
10 Correct 0 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 0 ms 2020 KB Output is correct
16 Correct 0 ms 2020 KB Output is correct
17 Correct 0 ms 2020 KB Output is correct
18 Correct 0 ms 2020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 0 ms 2020 KB Output is correct
9 Correct 0 ms 2020 KB Output is correct
10 Correct 0 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 0 ms 2020 KB Output is correct
16 Correct 0 ms 2020 KB Output is correct
17 Correct 0 ms 2020 KB Output is correct
18 Correct 0 ms 2020 KB Output is correct
19 Correct 0 ms 2020 KB Output is correct
20 Correct 0 ms 2020 KB Output is correct
21 Correct 0 ms 2020 KB Output is correct
22 Correct 0 ms 2168 KB Output is correct
23 Correct 0 ms 2176 KB Output is correct
24 Correct 0 ms 2168 KB Output is correct
25 Correct 0 ms 2176 KB Output is correct
26 Correct 0 ms 2176 KB Output is correct
27 Correct 0 ms 2020 KB Output is correct
28 Correct 0 ms 2020 KB Output is correct
29 Correct 0 ms 2020 KB Output is correct
30 Correct 0 ms 2176 KB Output is correct
31 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
4 Correct 23 ms 3592 KB Output is correct
5 Correct 56 ms 5932 KB Output is correct
6 Correct 73 ms 6912 KB Output is correct
7 Correct 93 ms 7880 KB Output is correct
8 Correct 153 ms 11792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 0 ms 2020 KB Output is correct
9 Correct 0 ms 2020 KB Output is correct
10 Correct 0 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 0 ms 2020 KB Output is correct
16 Correct 0 ms 2020 KB Output is correct
17 Correct 0 ms 2020 KB Output is correct
18 Correct 0 ms 2020 KB Output is correct
19 Correct 0 ms 2020 KB Output is correct
20 Correct 0 ms 2020 KB Output is correct
21 Correct 0 ms 2020 KB Output is correct
22 Correct 0 ms 2168 KB Output is correct
23 Correct 0 ms 2176 KB Output is correct
24 Correct 0 ms 2168 KB Output is correct
25 Correct 0 ms 2176 KB Output is correct
26 Correct 0 ms 2176 KB Output is correct
27 Correct 0 ms 2020 KB Output is correct
28 Correct 0 ms 2020 KB Output is correct
29 Correct 0 ms 2020 KB Output is correct
30 Correct 0 ms 2176 KB Output is correct
31 Correct 0 ms 2176 KB Output is correct
32 Correct 0 ms 2020 KB Output is correct
33 Correct 0 ms 2020 KB Output is correct
34 Correct 0 ms 2176 KB Output is correct
35 Correct 23 ms 3592 KB Output is correct
36 Correct 56 ms 5932 KB Output is correct
37 Correct 73 ms 6912 KB Output is correct
38 Correct 93 ms 7880 KB Output is correct
39 Correct 153 ms 11792 KB Output is correct
40 Correct 3 ms 2332 KB Output is correct
41 Correct 6 ms 2496 KB Output is correct
42 Correct 9 ms 2684 KB Output is correct
43 Correct 66 ms 5932 KB Output is correct
44 Correct 159 ms 11792 KB Output is correct
45 Correct 26 ms 3980 KB Output is correct
46 Correct 96 ms 7880 KB Output is correct
47 Correct 153 ms 11792 KB Output is correct
48 Correct 173 ms 11792 KB Output is correct
49 Correct 119 ms 11948 KB Output is correct
50 Correct 119 ms 11948 KB Output is correct