Submission #419307

# Submission time Handle Problem Language Result Execution time Memory
419307 2021-06-06T20:41:22 Z Runtime_error_ Cigle (COI21_cigle) C++14
100 / 100
868 ms 197176 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 5009;
int n,a[inf],dp[inf][inf],mx[inf],ans;

vector<pair<int,int> > v[inf];

int get(vector<pair<int,int> > &cur,int ub){
//    int ret = 0;
//    for(auto o:cur)
//        if(o.first <= ub)
//            ret = max(ret,o.second);
//        return ret;
    int idx = lower_bound(cur.begin(),cur.end(),make_pair(ub+1,-1))-cur.begin();
    if(idx-1 >=0 && cur[idx-1].first <= ub)
        return cur[idx-1].second;
    return 0;
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        int l = i,sum1 = a[l],sum2 = 0,cur = 0;
        for(int r = i+1;r<n;r++){
            sum2 += a[r];
            while(l>1 && sum1 + a[l-1] <= sum2)
                sum1 += a[l-1],l--;
            if(sum1 == sum2)cur++;
            dp[i][r+1] = dp[i][r];
            int mx = 0;
            if(l != 1)
                mx = get(v[i],l-2),dp[i][r+1] = max(dp[i][r+1],mx + cur);

           pair<int,int> tmp = (v[r+1].empty()?make_pair(0,0):v[r+1].back());
           tmp.first = i,tmp.second = max(tmp.second,dp[i][r+1]);
           v[r+1].push_back(tmp);
           ans = max(ans,dp[i][r+1]);
        }
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4172 KB Output is correct
2 Correct 7 ms 4172 KB Output is correct
3 Correct 8 ms 4260 KB Output is correct
4 Correct 7 ms 4172 KB Output is correct
5 Correct 8 ms 4172 KB Output is correct
6 Correct 8 ms 4172 KB Output is correct
7 Correct 8 ms 4172 KB Output is correct
8 Correct 8 ms 4252 KB Output is correct
9 Correct 8 ms 4172 KB Output is correct
10 Correct 7 ms 4172 KB Output is correct
11 Correct 9 ms 4172 KB Output is correct
12 Correct 7 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 7 ms 4172 KB Output is correct
22 Correct 7 ms 4172 KB Output is correct
23 Correct 8 ms 4260 KB Output is correct
24 Correct 7 ms 4172 KB Output is correct
25 Correct 8 ms 4172 KB Output is correct
26 Correct 8 ms 4172 KB Output is correct
27 Correct 8 ms 4172 KB Output is correct
28 Correct 8 ms 4252 KB Output is correct
29 Correct 8 ms 4172 KB Output is correct
30 Correct 7 ms 4172 KB Output is correct
31 Correct 9 ms 4172 KB Output is correct
32 Correct 7 ms 4172 KB Output is correct
33 Correct 7 ms 4252 KB Output is correct
34 Correct 9 ms 4172 KB Output is correct
35 Correct 8 ms 4172 KB Output is correct
36 Correct 8 ms 4172 KB Output is correct
37 Correct 8 ms 4224 KB Output is correct
38 Correct 8 ms 4172 KB Output is correct
39 Correct 8 ms 4172 KB Output is correct
40 Correct 8 ms 4164 KB Output is correct
41 Correct 8 ms 4192 KB Output is correct
42 Correct 8 ms 4172 KB Output is correct
43 Correct 7 ms 4172 KB Output is correct
44 Correct 8 ms 4192 KB Output is correct
45 Correct 7 ms 4172 KB Output is correct
46 Correct 7 ms 4256 KB Output is correct
47 Correct 8 ms 4172 KB Output is correct
48 Correct 7 ms 4172 KB Output is correct
49 Correct 8 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 7 ms 4172 KB Output is correct
22 Correct 7 ms 4172 KB Output is correct
23 Correct 8 ms 4260 KB Output is correct
24 Correct 7 ms 4172 KB Output is correct
25 Correct 8 ms 4172 KB Output is correct
26 Correct 8 ms 4172 KB Output is correct
27 Correct 8 ms 4172 KB Output is correct
28 Correct 8 ms 4252 KB Output is correct
29 Correct 8 ms 4172 KB Output is correct
30 Correct 7 ms 4172 KB Output is correct
31 Correct 9 ms 4172 KB Output is correct
32 Correct 7 ms 4172 KB Output is correct
33 Correct 7 ms 4252 KB Output is correct
34 Correct 9 ms 4172 KB Output is correct
35 Correct 8 ms 4172 KB Output is correct
36 Correct 8 ms 4172 KB Output is correct
37 Correct 8 ms 4224 KB Output is correct
38 Correct 8 ms 4172 KB Output is correct
39 Correct 8 ms 4172 KB Output is correct
40 Correct 8 ms 4164 KB Output is correct
41 Correct 8 ms 4192 KB Output is correct
42 Correct 8 ms 4172 KB Output is correct
43 Correct 7 ms 4172 KB Output is correct
44 Correct 8 ms 4192 KB Output is correct
45 Correct 7 ms 4172 KB Output is correct
46 Correct 7 ms 4256 KB Output is correct
47 Correct 8 ms 4172 KB Output is correct
48 Correct 7 ms 4172 KB Output is correct
49 Correct 8 ms 4172 KB Output is correct
50 Correct 805 ms 197028 KB Output is correct
51 Correct 803 ms 197008 KB Output is correct
52 Correct 854 ms 197176 KB Output is correct
53 Correct 808 ms 196964 KB Output is correct
54 Correct 806 ms 197036 KB Output is correct
55 Correct 797 ms 196984 KB Output is correct
56 Correct 823 ms 196920 KB Output is correct
57 Correct 805 ms 197000 KB Output is correct
58 Correct 837 ms 196944 KB Output is correct
59 Correct 801 ms 197064 KB Output is correct
60 Correct 817 ms 196972 KB Output is correct
61 Correct 794 ms 197112 KB Output is correct
62 Correct 792 ms 196984 KB Output is correct
63 Correct 799 ms 197080 KB Output is correct
64 Correct 864 ms 196956 KB Output is correct
65 Correct 838 ms 196960 KB Output is correct
66 Correct 838 ms 196944 KB Output is correct
67 Correct 863 ms 196920 KB Output is correct
68 Correct 854 ms 197020 KB Output is correct
69 Correct 844 ms 196932 KB Output is correct
70 Correct 856 ms 196976 KB Output is correct
71 Correct 868 ms 196984 KB Output is correct
72 Correct 839 ms 197064 KB Output is correct