Submission #158748

# Submission time Handle Problem Language Result Execution time Memory
158748 2019-10-18T15:30:26 Z koste4ka Bigger segments (IZhO19_segments) C++14
73 / 100
34 ms 14072 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int N = 2e5 + 11;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll a[N];

lll dp[N];

int k[N];

int ans[N];

lll pref[N];

lll get(int l, int r) {
    lll ans = pref[r];
    if (l) {
        ans -= pref[l - 1];
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pref[i] = a[i];
        ans[i] = 1;
        dp[i] = a[i];
        k[i] = 1;
        if (i) {
            dp[i] += dp[i - 1];
            k[i] += k[i - 1];
            pref[i] += pref[i - 1];
        }
    }
    int l, r;
    for (int i = 0; i + 1 < n; ++i) {
        if (dp[i + 1] > dp[i] + a[i + 1]) {
            dp[i + 1] = dp[i] + a[i + 1];
            k[i + 1] = k[i] + 1;
            ans[i + 1] = ans[i];
        }
        l = i + 1;
        r = n - 1;
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (get(i + 1, mid) >= dp[i]) {
                r = mid;
            } else {
                l = mid;
            }
        }
        if (get(i + 1, l) < dp[i]) {
            l = r;
        }
        if (get(i + 1, l) >= dp[i]) {
            if (dp[l] > get(i + 1, l)) {
                dp[l] = get(i + 1, l);
                k[l] = l - i;
                ans[l] = ans[i] + 1;
            }
        }
    }
    cout << ans[n - 1];
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 500 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 500 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 508 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 3 ms 508 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 500 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 508 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 3 ms 508 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 18 ms 3832 KB Output is correct
47 Correct 21 ms 3960 KB Output is correct
48 Correct 22 ms 4264 KB Output is correct
49 Correct 22 ms 4472 KB Output is correct
50 Correct 24 ms 4472 KB Output is correct
51 Correct 25 ms 4468 KB Output is correct
52 Correct 14 ms 2424 KB Output is correct
53 Correct 9 ms 1656 KB Output is correct
54 Correct 19 ms 3704 KB Output is correct
55 Correct 25 ms 4344 KB Output is correct
56 Correct 17 ms 3960 KB Output is correct
57 Correct 17 ms 3832 KB Output is correct
58 Correct 18 ms 3960 KB Output is correct
59 Correct 18 ms 4088 KB Output is correct
60 Correct 18 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 500 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 508 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 3 ms 508 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 18 ms 3832 KB Output is correct
47 Correct 21 ms 3960 KB Output is correct
48 Correct 22 ms 4264 KB Output is correct
49 Correct 22 ms 4472 KB Output is correct
50 Correct 24 ms 4472 KB Output is correct
51 Correct 25 ms 4468 KB Output is correct
52 Correct 14 ms 2424 KB Output is correct
53 Correct 9 ms 1656 KB Output is correct
54 Correct 19 ms 3704 KB Output is correct
55 Correct 25 ms 4344 KB Output is correct
56 Correct 17 ms 3960 KB Output is correct
57 Correct 17 ms 3832 KB Output is correct
58 Correct 18 ms 3960 KB Output is correct
59 Correct 18 ms 4088 KB Output is correct
60 Correct 18 ms 4088 KB Output is correct
61 Runtime error 34 ms 14072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
62 Halted 0 ms 0 KB -