Submission #344371

# Submission time Handle Problem Language Result Execution time Memory
344371 2021-01-05T14:47:14 Z Redhood Bigger segments (IZhO19_segments) C++14
100 / 100
142 ms 47724 KB
#include<bits/stdc++.h>

#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define pb push_back
#define len(x) (int)(x).size()


using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;
    vector < int > a(n);
    for(auto &i : a)
        cin >> i;
    vector < ll > pref(n + 1);
    for(int i = 0; i < n; ++i){
        pref[i + 1] = pref[i] + a[i];
    }


    vector < pair < int , int > > dp(n + 1 , {0 , 0});
    dp[0] = {0 , 0};


    vector < vector < int > > add(n + 2);

    pair < int , int > cur = {0 , 0};
    for(int i = 0; i <= n; ++i){
        /// lulz
        /// calc dp
        if(i != 0){
            for(auto u : add[i])
                if(cur.fi < dp[u].fi + 1)
                    cur.fi = dp[u].fi + 1 , cur.se = u;
                else if(cur.fi == dp[u].fi + 1)
                    cur.se = max(cur.se , u);
            dp[i] = {cur.fi , pref[i] - pref[cur.se]};
        }
        int frst = lower_bound(all(pref) , pref[i]+dp[i].se) - pref.begin();
        frst = max(frst , i + 1);
        add[frst].pb(i);
    }
//    cout << " DP \n";
//    for(int i = 0; i <= n; ++i){
//        cout << dp[i].fi << ' ' << dp[i].se << '\n';
//    }
    cout << dp[n].fi << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 620 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 1 ms 620 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 1 ms 620 KB Output is correct
43 Correct 1 ms 620 KB Output is correct
44 Correct 1 ms 620 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 620 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 1 ms 620 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 1 ms 620 KB Output is correct
43 Correct 1 ms 620 KB Output is correct
44 Correct 1 ms 620 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 15 ms 7404 KB Output is correct
47 Correct 21 ms 8172 KB Output is correct
48 Correct 27 ms 8684 KB Output is correct
49 Correct 26 ms 9708 KB Output is correct
50 Correct 25 ms 9964 KB Output is correct
51 Correct 28 ms 8812 KB Output is correct
52 Correct 15 ms 4588 KB Output is correct
53 Correct 9 ms 2924 KB Output is correct
54 Correct 24 ms 8044 KB Output is correct
55 Correct 28 ms 9452 KB Output is correct
56 Correct 23 ms 9452 KB Output is correct
57 Correct 19 ms 8424 KB Output is correct
58 Correct 21 ms 8808 KB Output is correct
59 Correct 23 ms 9580 KB Output is correct
60 Correct 23 ms 9452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 620 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 1 ms 620 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 1 ms 620 KB Output is correct
43 Correct 1 ms 620 KB Output is correct
44 Correct 1 ms 620 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 15 ms 7404 KB Output is correct
47 Correct 21 ms 8172 KB Output is correct
48 Correct 27 ms 8684 KB Output is correct
49 Correct 26 ms 9708 KB Output is correct
50 Correct 25 ms 9964 KB Output is correct
51 Correct 28 ms 8812 KB Output is correct
52 Correct 15 ms 4588 KB Output is correct
53 Correct 9 ms 2924 KB Output is correct
54 Correct 24 ms 8044 KB Output is correct
55 Correct 28 ms 9452 KB Output is correct
56 Correct 23 ms 9452 KB Output is correct
57 Correct 19 ms 8424 KB Output is correct
58 Correct 21 ms 8808 KB Output is correct
59 Correct 23 ms 9580 KB Output is correct
60 Correct 23 ms 9452 KB Output is correct
61 Correct 77 ms 34020 KB Output is correct
62 Correct 80 ms 35324 KB Output is correct
63 Correct 104 ms 39072 KB Output is correct
64 Correct 142 ms 43884 KB Output is correct
65 Correct 130 ms 47724 KB Output is correct
66 Correct 142 ms 42348 KB Output is correct
67 Correct 117 ms 34284 KB Output is correct
68 Correct 60 ms 17516 KB Output is correct
69 Correct 119 ms 38508 KB Output is correct
70 Correct 133 ms 45548 KB Output is correct
71 Correct 108 ms 45292 KB Output is correct
72 Correct 101 ms 41056 KB Output is correct
73 Correct 112 ms 44520 KB Output is correct
74 Correct 116 ms 46700 KB Output is correct
75 Correct 117 ms 46700 KB Output is correct