답안 #544144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544144 2022-04-01T08:25:34 Z robertbarbu27 Cigle (COI21_cigle) C++14
100 / 100
193 ms 67428 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
ifstream f("teroristi2.in");
ofstream g("teroristi2.out");
int N;
int h[5005];
int dp[5005][5005];
int sp[5005];
int bruteforce()
{
    for(int fin=1; fin<=N; fin++)
    {
        for(int start=fin; start>=1; start--)
        {
            vector<int> sp(N+5,0);
            for(int j=fin; j>=start; j--)
            {
                sp[j]=sp[j+1]+h[j];
            }
            int sum=0,layers=0,cnt=fin;
            for(int fin2=fin+1; fin2<=N; fin2++)
            {
                ///dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers)
                sum+=h[fin2];

                dp[fin+1][fin2]=max(dp[fin+1][fin2],dp[start][fin]+layers);
                while(sum>sp[cnt]&&cnt>start+1)
                {
                    cnt--;
                }
                if(sum==sp[cnt]&&cnt!=start)
                {
                    layers++;
                }


            }
        }
    }
    int rez=0;
    for(int i=1; i<=N; i++)
    {
        rez=max(rez,dp[i][N]);
        // cout<<i<<" "<<dp[i][N]<<'\n';
    }
    return rez;
}
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>N;
    for(int i=1; i<=N; i++)
    {
        cin>>h[i];
        sp[i]=sp[i-1]+h[i];
    }
    for(int fin=1; fin<=N; fin++)
    {
        vector<int> aux(N+5,0);
        for(int start=1;start<=fin;start++)
        {
            aux[start]=max(aux[start-1],dp[start][fin]);
        }
        int start=fin-1;
        int mxdp=0,layers=0;
        for(int fin2=fin+1;fin2<=N;fin2++)
        {
            dp[fin][fin2]=mxdp;
            while(start&&sp[fin2]-sp[fin]>sp[fin]-sp[start])
            {
                start--;
            }
            if(start&&sp[fin2]-sp[fin]==sp[fin]-sp[start])
            {
                layers++;
                mxdp=max(mxdp,aux[start-1]+layers);
            }
        }
    }
    int rez=0;
    for(int i=0; i<N; i++)
    {
        rez=max(rez,dp[i][N]);
    }
    cout<<rez;






}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 3 ms 2772 KB Output is correct
5 Correct 3 ms 2772 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2752 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 3 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 3 ms 2772 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 3 ms 2772 KB Output is correct
30 Correct 3 ms 2752 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2772 KB Output is correct
43 Correct 3 ms 2772 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 3 ms 2772 KB Output is correct
49 Correct 4 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 3 ms 2772 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 3 ms 2772 KB Output is correct
30 Correct 3 ms 2752 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2772 KB Output is correct
43 Correct 3 ms 2772 KB Output is correct
44 Correct 3 ms 2772 KB Output is correct
45 Correct 3 ms 2772 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 3 ms 2772 KB Output is correct
48 Correct 3 ms 2772 KB Output is correct
49 Correct 4 ms 2772 KB Output is correct
50 Correct 141 ms 67284 KB Output is correct
51 Correct 148 ms 67412 KB Output is correct
52 Correct 153 ms 67312 KB Output is correct
53 Correct 154 ms 67280 KB Output is correct
54 Correct 147 ms 67356 KB Output is correct
55 Correct 151 ms 67396 KB Output is correct
56 Correct 187 ms 67268 KB Output is correct
57 Correct 187 ms 67364 KB Output is correct
58 Correct 189 ms 67360 KB Output is correct
59 Correct 186 ms 67316 KB Output is correct
60 Correct 193 ms 67276 KB Output is correct
61 Correct 174 ms 67276 KB Output is correct
62 Correct 164 ms 67364 KB Output is correct
63 Correct 155 ms 67424 KB Output is correct
64 Correct 161 ms 67276 KB Output is correct
65 Correct 162 ms 67276 KB Output is correct
66 Correct 167 ms 67280 KB Output is correct
67 Correct 146 ms 67292 KB Output is correct
68 Correct 147 ms 67312 KB Output is correct
69 Correct 148 ms 67276 KB Output is correct
70 Correct 177 ms 67376 KB Output is correct
71 Correct 186 ms 67428 KB Output is correct
72 Correct 171 ms 67368 KB Output is correct