Submission #467437

# Submission time Handle Problem Language Result Execution time Memory
467437 2021-08-22T23:24:25 Z julian33 Cigle (COI21_cigle) C++14
48 / 100
1000 ms 10424 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=5e3+5; //make sure this is right
const int mod=1e9+7;

int dp[mxN][mxN],a[mxN];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n; cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            int pre=i-j;
            int k=i-j+1;
            int p=pre;
            int s1=0; int s2=0;
            dp[i][j]=dp[pre][1];
            int cnt=0;
            while(p && k<i){
                if(s1+a[p]<=s2+a[k]){
                    s1+=a[p--];
                } else{
                    s2+=a[k++];
                }
                if(s1==s2){
                    cnt++;
                    maxa(dp[i][j],cnt+dp[pre][pre-p+1]);
                }
            }
            deb(i,j,dp[i][j],cnt);
        }
        for(int j=i-1;j>=1;j--)
            maxa(dp[i][j],dp[i][j+1]);
    }
    cout<<dp[n][1]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 580 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2744 KB Output is correct
2 Correct 47 ms 2780 KB Output is correct
3 Correct 45 ms 2732 KB Output is correct
4 Correct 56 ms 2752 KB Output is correct
5 Correct 54 ms 2924 KB Output is correct
6 Correct 100 ms 2812 KB Output is correct
7 Correct 105 ms 2764 KB Output is correct
8 Correct 105 ms 2736 KB Output is correct
9 Correct 104 ms 2812 KB Output is correct
10 Correct 72 ms 2840 KB Output is correct
11 Correct 87 ms 2756 KB Output is correct
12 Correct 68 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 580 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 580 KB Output is correct
21 Correct 46 ms 2744 KB Output is correct
22 Correct 47 ms 2780 KB Output is correct
23 Correct 45 ms 2732 KB Output is correct
24 Correct 56 ms 2752 KB Output is correct
25 Correct 54 ms 2924 KB Output is correct
26 Correct 100 ms 2812 KB Output is correct
27 Correct 105 ms 2764 KB Output is correct
28 Correct 105 ms 2736 KB Output is correct
29 Correct 104 ms 2812 KB Output is correct
30 Correct 72 ms 2840 KB Output is correct
31 Correct 87 ms 2756 KB Output is correct
32 Correct 68 ms 2764 KB Output is correct
33 Correct 44 ms 2756 KB Output is correct
34 Correct 47 ms 2756 KB Output is correct
35 Correct 49 ms 2768 KB Output is correct
36 Correct 50 ms 2748 KB Output is correct
37 Correct 101 ms 2760 KB Output is correct
38 Correct 104 ms 2708 KB Output is correct
39 Correct 137 ms 2916 KB Output is correct
40 Correct 120 ms 2724 KB Output is correct
41 Correct 93 ms 2828 KB Output is correct
42 Correct 82 ms 2736 KB Output is correct
43 Correct 79 ms 2776 KB Output is correct
44 Correct 113 ms 2716 KB Output is correct
45 Correct 83 ms 2760 KB Output is correct
46 Correct 87 ms 2708 KB Output is correct
47 Correct 106 ms 2756 KB Output is correct
48 Correct 85 ms 2756 KB Output is correct
49 Correct 73 ms 2800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 580 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 580 KB Output is correct
21 Correct 46 ms 2744 KB Output is correct
22 Correct 47 ms 2780 KB Output is correct
23 Correct 45 ms 2732 KB Output is correct
24 Correct 56 ms 2752 KB Output is correct
25 Correct 54 ms 2924 KB Output is correct
26 Correct 100 ms 2812 KB Output is correct
27 Correct 105 ms 2764 KB Output is correct
28 Correct 105 ms 2736 KB Output is correct
29 Correct 104 ms 2812 KB Output is correct
30 Correct 72 ms 2840 KB Output is correct
31 Correct 87 ms 2756 KB Output is correct
32 Correct 68 ms 2764 KB Output is correct
33 Correct 44 ms 2756 KB Output is correct
34 Correct 47 ms 2756 KB Output is correct
35 Correct 49 ms 2768 KB Output is correct
36 Correct 50 ms 2748 KB Output is correct
37 Correct 101 ms 2760 KB Output is correct
38 Correct 104 ms 2708 KB Output is correct
39 Correct 137 ms 2916 KB Output is correct
40 Correct 120 ms 2724 KB Output is correct
41 Correct 93 ms 2828 KB Output is correct
42 Correct 82 ms 2736 KB Output is correct
43 Correct 79 ms 2776 KB Output is correct
44 Correct 113 ms 2716 KB Output is correct
45 Correct 83 ms 2760 KB Output is correct
46 Correct 87 ms 2708 KB Output is correct
47 Correct 106 ms 2756 KB Output is correct
48 Correct 85 ms 2756 KB Output is correct
49 Correct 73 ms 2800 KB Output is correct
50 Execution timed out 1089 ms 10424 KB Time limit exceeded
51 Halted 0 ms 0 KB -