답안 #467439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467439 2021-08-22T23:25:27 Z julian33 Cigle (COI21_cigle) C++14
0 / 100
5 ms 7756 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],cnt[mxN][mxN],ptr[mxN][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];
    int ans=0;
    for(int i=1;i<=n;i++){
        int p=i-1;
        int s1=0; int s2=0;
        for(int j=i;j<=n;j++){
            dp[i][j]=dp[i-1][i-1];
            cnt[i][j]=cnt[i][j-1];
            s1+=a[j];
            while(p && s2+a[p]<=s1)
                s2+=a[p--];
            if(s1==s2)
                cnt[i][j]++;
            ptr[i][j]=p;
            maxa(dp[i][j],cnt[i][j-1]+dp[ptr[i][j-1]][i-1]);
            maxa(dp[i][j],dp[i-1][j]);
            maxa(ans,dp[i][j]);
        }
    }
    cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7756 KB Output is correct
2 Incorrect 5 ms 7756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -