Submission #405594

# Submission time Handle Problem Language Result Execution time Memory
405594 2021-05-16T14:57:03 Z sad Cigle (COI21_cigle) C++14
100 / 100
963 ms 333216 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int n;const int N=5100,M=5000*5009;
pair<int,int>dp[N][N];int a[N],prf[M];
pair<int,int>mxdp[N][N];
vector<int>v;
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;int ans=0;int rw=0;
    for(int i=1;i<n+1;i++)cin>>a[i];memset(prf,-1,sizeof prf);
    for(int m=1;m<=n;m++)
    {
        for(auto it:v)prf[it]=-1;
        v.clear();
        int re=0;v.pb(0);
        for(int i=m;i>0;i--)
        {
            re+=a[i];v.pb(re);
            prf[re]=i;
        }
        re=0;
        dp[m][m]={0,n+1};
        mxdp[m][1]={dp[m][1].fi,1};
        for(int i=2;i<m;i++)
        {

            if(dp[m][i].fi>mxdp[m][i-1].fi)
            {
                mxdp[m][i]={dp[m][i].fi,i};continue;
            }
            mxdp[m][i]=mxdp[m][i-1];
        }
        dp[m+1][m]=mxdp[m][m-1];ans=max(ans,dp[m+1][m].fi);
        rw=0;
        for(int r=m+2;r<n+1;r++)
        {re+=a[r-1];
            if(prf[re]!=-1)rw++;
            int last=dp[r-1][m].se;
            int mx=dp[r-1][m].fi;
            if(prf[re]==-1||prf[re]-2<0)
            {
                dp[r][m]=dp[r-1][m];
                ans=max(ans,mx);continue;
            }
            pair<int,int>z=mxdp[m][prf[re]-2];
            z.fi+=rw;
            if(z.fi>mx)
            {
                dp[r][m]=z;
                ans=max(ans,z.fi);continue;
            }
            dp[r][m]=dp[r-1][m];
            ans=max(ans,mx);
            continue;
        }
    }
    cout<<ans;

}
/*
10
2 3 2 1 1 5 5 2 5 1
*/

Compilation message

cigle.cpp: In function 'int main()':
cigle.cpp:14:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |     for(int i=1;i<n+1;i++)cin>>a[i];memset(prf,-1,sizeof prf);
      |     ^~~
cigle.cpp:14:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |     for(int i=1;i<n+1;i++)cin>>a[i];memset(prf,-1,sizeof prf);
      |                                     ^~~~~~
cigle.cpp:42:17: warning: unused variable 'last' [-Wunused-variable]
   42 |             int last=dp[r-1][m].se;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 98512 KB Output is correct
2 Correct 46 ms 98408 KB Output is correct
3 Correct 47 ms 98396 KB Output is correct
4 Correct 43 ms 98460 KB Output is correct
5 Correct 44 ms 98440 KB Output is correct
6 Correct 45 ms 98508 KB Output is correct
7 Correct 43 ms 98376 KB Output is correct
8 Correct 47 ms 98536 KB Output is correct
9 Correct 45 ms 98432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 98512 KB Output is correct
2 Correct 46 ms 98408 KB Output is correct
3 Correct 47 ms 98396 KB Output is correct
4 Correct 43 ms 98460 KB Output is correct
5 Correct 44 ms 98440 KB Output is correct
6 Correct 45 ms 98508 KB Output is correct
7 Correct 43 ms 98376 KB Output is correct
8 Correct 47 ms 98536 KB Output is correct
9 Correct 45 ms 98432 KB Output is correct
10 Correct 50 ms 98996 KB Output is correct
11 Correct 46 ms 99008 KB Output is correct
12 Correct 46 ms 98924 KB Output is correct
13 Correct 49 ms 99016 KB Output is correct
14 Correct 45 ms 98992 KB Output is correct
15 Correct 44 ms 98940 KB Output is correct
16 Correct 46 ms 99012 KB Output is correct
17 Correct 49 ms 98972 KB Output is correct
18 Correct 50 ms 98908 KB Output is correct
19 Correct 49 ms 99012 KB Output is correct
20 Correct 45 ms 98920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 104344 KB Output is correct
2 Correct 50 ms 104268 KB Output is correct
3 Correct 50 ms 104268 KB Output is correct
4 Correct 48 ms 104360 KB Output is correct
5 Correct 50 ms 104252 KB Output is correct
6 Correct 48 ms 104332 KB Output is correct
7 Correct 49 ms 104316 KB Output is correct
8 Correct 57 ms 104260 KB Output is correct
9 Correct 51 ms 104300 KB Output is correct
10 Correct 49 ms 104260 KB Output is correct
11 Correct 49 ms 104396 KB Output is correct
12 Correct 49 ms 104364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 98512 KB Output is correct
2 Correct 46 ms 98408 KB Output is correct
3 Correct 47 ms 98396 KB Output is correct
4 Correct 43 ms 98460 KB Output is correct
5 Correct 44 ms 98440 KB Output is correct
6 Correct 45 ms 98508 KB Output is correct
7 Correct 43 ms 98376 KB Output is correct
8 Correct 47 ms 98536 KB Output is correct
9 Correct 45 ms 98432 KB Output is correct
10 Correct 50 ms 98996 KB Output is correct
11 Correct 46 ms 99008 KB Output is correct
12 Correct 46 ms 98924 KB Output is correct
13 Correct 49 ms 99016 KB Output is correct
14 Correct 45 ms 98992 KB Output is correct
15 Correct 44 ms 98940 KB Output is correct
16 Correct 46 ms 99012 KB Output is correct
17 Correct 49 ms 98972 KB Output is correct
18 Correct 50 ms 98908 KB Output is correct
19 Correct 49 ms 99012 KB Output is correct
20 Correct 45 ms 98920 KB Output is correct
21 Correct 50 ms 104344 KB Output is correct
22 Correct 50 ms 104268 KB Output is correct
23 Correct 50 ms 104268 KB Output is correct
24 Correct 48 ms 104360 KB Output is correct
25 Correct 50 ms 104252 KB Output is correct
26 Correct 48 ms 104332 KB Output is correct
27 Correct 49 ms 104316 KB Output is correct
28 Correct 57 ms 104260 KB Output is correct
29 Correct 51 ms 104300 KB Output is correct
30 Correct 49 ms 104260 KB Output is correct
31 Correct 49 ms 104396 KB Output is correct
32 Correct 49 ms 104364 KB Output is correct
33 Correct 58 ms 104304 KB Output is correct
34 Correct 48 ms 104352 KB Output is correct
35 Correct 59 ms 104292 KB Output is correct
36 Correct 48 ms 104272 KB Output is correct
37 Correct 49 ms 104268 KB Output is correct
38 Correct 50 ms 104404 KB Output is correct
39 Correct 52 ms 104252 KB Output is correct
40 Correct 53 ms 104268 KB Output is correct
41 Correct 51 ms 104348 KB Output is correct
42 Correct 52 ms 104260 KB Output is correct
43 Correct 55 ms 104344 KB Output is correct
44 Correct 52 ms 104260 KB Output is correct
45 Correct 50 ms 104232 KB Output is correct
46 Correct 59 ms 104320 KB Output is correct
47 Correct 49 ms 104260 KB Output is correct
48 Correct 53 ms 104260 KB Output is correct
49 Correct 51 ms 104236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 98512 KB Output is correct
2 Correct 46 ms 98408 KB Output is correct
3 Correct 47 ms 98396 KB Output is correct
4 Correct 43 ms 98460 KB Output is correct
5 Correct 44 ms 98440 KB Output is correct
6 Correct 45 ms 98508 KB Output is correct
7 Correct 43 ms 98376 KB Output is correct
8 Correct 47 ms 98536 KB Output is correct
9 Correct 45 ms 98432 KB Output is correct
10 Correct 50 ms 98996 KB Output is correct
11 Correct 46 ms 99008 KB Output is correct
12 Correct 46 ms 98924 KB Output is correct
13 Correct 49 ms 99016 KB Output is correct
14 Correct 45 ms 98992 KB Output is correct
15 Correct 44 ms 98940 KB Output is correct
16 Correct 46 ms 99012 KB Output is correct
17 Correct 49 ms 98972 KB Output is correct
18 Correct 50 ms 98908 KB Output is correct
19 Correct 49 ms 99012 KB Output is correct
20 Correct 45 ms 98920 KB Output is correct
21 Correct 50 ms 104344 KB Output is correct
22 Correct 50 ms 104268 KB Output is correct
23 Correct 50 ms 104268 KB Output is correct
24 Correct 48 ms 104360 KB Output is correct
25 Correct 50 ms 104252 KB Output is correct
26 Correct 48 ms 104332 KB Output is correct
27 Correct 49 ms 104316 KB Output is correct
28 Correct 57 ms 104260 KB Output is correct
29 Correct 51 ms 104300 KB Output is correct
30 Correct 49 ms 104260 KB Output is correct
31 Correct 49 ms 104396 KB Output is correct
32 Correct 49 ms 104364 KB Output is correct
33 Correct 58 ms 104304 KB Output is correct
34 Correct 48 ms 104352 KB Output is correct
35 Correct 59 ms 104292 KB Output is correct
36 Correct 48 ms 104272 KB Output is correct
37 Correct 49 ms 104268 KB Output is correct
38 Correct 50 ms 104404 KB Output is correct
39 Correct 52 ms 104252 KB Output is correct
40 Correct 53 ms 104268 KB Output is correct
41 Correct 51 ms 104348 KB Output is correct
42 Correct 52 ms 104260 KB Output is correct
43 Correct 55 ms 104344 KB Output is correct
44 Correct 52 ms 104260 KB Output is correct
45 Correct 50 ms 104232 KB Output is correct
46 Correct 59 ms 104320 KB Output is correct
47 Correct 49 ms 104260 KB Output is correct
48 Correct 53 ms 104260 KB Output is correct
49 Correct 51 ms 104236 KB Output is correct
50 Correct 452 ms 333104 KB Output is correct
51 Correct 439 ms 332980 KB Output is correct
52 Correct 465 ms 333072 KB Output is correct
53 Correct 459 ms 333124 KB Output is correct
54 Correct 458 ms 333084 KB Output is correct
55 Correct 460 ms 333108 KB Output is correct
56 Correct 505 ms 333036 KB Output is correct
57 Correct 477 ms 333132 KB Output is correct
58 Correct 484 ms 333164 KB Output is correct
59 Correct 502 ms 333124 KB Output is correct
60 Correct 963 ms 333112 KB Output is correct
61 Correct 824 ms 333076 KB Output is correct
62 Correct 858 ms 333096 KB Output is correct
63 Correct 559 ms 333040 KB Output is correct
64 Correct 577 ms 333200 KB Output is correct
65 Correct 646 ms 332980 KB Output is correct
66 Correct 729 ms 333016 KB Output is correct
67 Correct 712 ms 333072 KB Output is correct
68 Correct 729 ms 333032 KB Output is correct
69 Correct 818 ms 333064 KB Output is correct
70 Correct 898 ms 333004 KB Output is correct
71 Correct 834 ms 333216 KB Output is correct
72 Correct 664 ms 333096 KB Output is correct