답안 #405582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405582 2021-05-16T14:50:24 Z sad Cigle (COI21_cigle) C++14
48 / 100
587 ms 24348 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=510,M=500*5009;
pair<int,int>dp[N][N];int a[N],prf[M];
pair<int,int>mxdp[N][N];
int main()
{
    cin>>n;int ans=0;int rw=0;
    for(int i=1;i<n+1;i++)cin>>a[i];
    for(int m=1;m<=n;m++)
    {
        memset(prf,-1,sizeof prf);
        int re=0;
        for(int i=m;i>0;i--)
        {
            re+=a[i];
            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:40:17: warning: unused variable 'last' [-Wunused-variable]
   40 |             int last=dp[r-1][m].se;
      |                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10188 KB Output is correct
2 Correct 25 ms 10236 KB Output is correct
3 Correct 25 ms 10212 KB Output is correct
4 Correct 26 ms 10232 KB Output is correct
5 Correct 28 ms 10216 KB Output is correct
6 Correct 25 ms 10224 KB Output is correct
7 Correct 26 ms 10188 KB Output is correct
8 Correct 30 ms 10216 KB Output is correct
9 Correct 28 ms 10228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10188 KB Output is correct
2 Correct 25 ms 10236 KB Output is correct
3 Correct 25 ms 10212 KB Output is correct
4 Correct 26 ms 10232 KB Output is correct
5 Correct 28 ms 10216 KB Output is correct
6 Correct 25 ms 10224 KB Output is correct
7 Correct 26 ms 10188 KB Output is correct
8 Correct 30 ms 10216 KB Output is correct
9 Correct 28 ms 10228 KB Output is correct
10 Correct 99 ms 10652 KB Output is correct
11 Correct 90 ms 10712 KB Output is correct
12 Correct 96 ms 10720 KB Output is correct
13 Correct 91 ms 10704 KB Output is correct
14 Correct 97 ms 10692 KB Output is correct
15 Correct 92 ms 10820 KB Output is correct
16 Correct 91 ms 10720 KB Output is correct
17 Correct 89 ms 10692 KB Output is correct
18 Correct 90 ms 10684 KB Output is correct
19 Correct 87 ms 10828 KB Output is correct
20 Correct 91 ms 10820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 14112 KB Output is correct
2 Correct 503 ms 14160 KB Output is correct
3 Correct 530 ms 14104 KB Output is correct
4 Correct 587 ms 14020 KB Output is correct
5 Correct 579 ms 14052 KB Output is correct
6 Correct 563 ms 14148 KB Output is correct
7 Correct 507 ms 13980 KB Output is correct
8 Correct 529 ms 14112 KB Output is correct
9 Correct 534 ms 14044 KB Output is correct
10 Correct 558 ms 14092 KB Output is correct
11 Correct 538 ms 14020 KB Output is correct
12 Correct 521 ms 14068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10188 KB Output is correct
2 Correct 25 ms 10236 KB Output is correct
3 Correct 25 ms 10212 KB Output is correct
4 Correct 26 ms 10232 KB Output is correct
5 Correct 28 ms 10216 KB Output is correct
6 Correct 25 ms 10224 KB Output is correct
7 Correct 26 ms 10188 KB Output is correct
8 Correct 30 ms 10216 KB Output is correct
9 Correct 28 ms 10228 KB Output is correct
10 Correct 99 ms 10652 KB Output is correct
11 Correct 90 ms 10712 KB Output is correct
12 Correct 96 ms 10720 KB Output is correct
13 Correct 91 ms 10704 KB Output is correct
14 Correct 97 ms 10692 KB Output is correct
15 Correct 92 ms 10820 KB Output is correct
16 Correct 91 ms 10720 KB Output is correct
17 Correct 89 ms 10692 KB Output is correct
18 Correct 90 ms 10684 KB Output is correct
19 Correct 87 ms 10828 KB Output is correct
20 Correct 91 ms 10820 KB Output is correct
21 Correct 572 ms 14112 KB Output is correct
22 Correct 503 ms 14160 KB Output is correct
23 Correct 530 ms 14104 KB Output is correct
24 Correct 587 ms 14020 KB Output is correct
25 Correct 579 ms 14052 KB Output is correct
26 Correct 563 ms 14148 KB Output is correct
27 Correct 507 ms 13980 KB Output is correct
28 Correct 529 ms 14112 KB Output is correct
29 Correct 534 ms 14044 KB Output is correct
30 Correct 558 ms 14092 KB Output is correct
31 Correct 538 ms 14020 KB Output is correct
32 Correct 521 ms 14068 KB Output is correct
33 Correct 560 ms 13996 KB Output is correct
34 Correct 544 ms 14112 KB Output is correct
35 Correct 519 ms 14156 KB Output is correct
36 Correct 531 ms 14020 KB Output is correct
37 Correct 530 ms 14064 KB Output is correct
38 Correct 532 ms 14060 KB Output is correct
39 Correct 515 ms 14028 KB Output is correct
40 Correct 524 ms 14136 KB Output is correct
41 Correct 516 ms 14156 KB Output is correct
42 Correct 522 ms 14052 KB Output is correct
43 Correct 524 ms 14016 KB Output is correct
44 Correct 536 ms 14112 KB Output is correct
45 Correct 535 ms 14036 KB Output is correct
46 Correct 521 ms 14108 KB Output is correct
47 Correct 508 ms 14020 KB Output is correct
48 Correct 569 ms 14112 KB Output is correct
49 Correct 525 ms 14140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10188 KB Output is correct
2 Correct 25 ms 10236 KB Output is correct
3 Correct 25 ms 10212 KB Output is correct
4 Correct 26 ms 10232 KB Output is correct
5 Correct 28 ms 10216 KB Output is correct
6 Correct 25 ms 10224 KB Output is correct
7 Correct 26 ms 10188 KB Output is correct
8 Correct 30 ms 10216 KB Output is correct
9 Correct 28 ms 10228 KB Output is correct
10 Correct 99 ms 10652 KB Output is correct
11 Correct 90 ms 10712 KB Output is correct
12 Correct 96 ms 10720 KB Output is correct
13 Correct 91 ms 10704 KB Output is correct
14 Correct 97 ms 10692 KB Output is correct
15 Correct 92 ms 10820 KB Output is correct
16 Correct 91 ms 10720 KB Output is correct
17 Correct 89 ms 10692 KB Output is correct
18 Correct 90 ms 10684 KB Output is correct
19 Correct 87 ms 10828 KB Output is correct
20 Correct 91 ms 10820 KB Output is correct
21 Correct 572 ms 14112 KB Output is correct
22 Correct 503 ms 14160 KB Output is correct
23 Correct 530 ms 14104 KB Output is correct
24 Correct 587 ms 14020 KB Output is correct
25 Correct 579 ms 14052 KB Output is correct
26 Correct 563 ms 14148 KB Output is correct
27 Correct 507 ms 13980 KB Output is correct
28 Correct 529 ms 14112 KB Output is correct
29 Correct 534 ms 14044 KB Output is correct
30 Correct 558 ms 14092 KB Output is correct
31 Correct 538 ms 14020 KB Output is correct
32 Correct 521 ms 14068 KB Output is correct
33 Correct 560 ms 13996 KB Output is correct
34 Correct 544 ms 14112 KB Output is correct
35 Correct 519 ms 14156 KB Output is correct
36 Correct 531 ms 14020 KB Output is correct
37 Correct 530 ms 14064 KB Output is correct
38 Correct 532 ms 14060 KB Output is correct
39 Correct 515 ms 14028 KB Output is correct
40 Correct 524 ms 14136 KB Output is correct
41 Correct 516 ms 14156 KB Output is correct
42 Correct 522 ms 14052 KB Output is correct
43 Correct 524 ms 14016 KB Output is correct
44 Correct 536 ms 14112 KB Output is correct
45 Correct 535 ms 14036 KB Output is correct
46 Correct 521 ms 14108 KB Output is correct
47 Correct 508 ms 14020 KB Output is correct
48 Correct 569 ms 14112 KB Output is correct
49 Correct 525 ms 14140 KB Output is correct
50 Runtime error 21 ms 24348 KB Execution killed with signal 11
51 Halted 0 ms 0 KB -