Submission #997617

#TimeUsernameProblemLanguageResultExecution timeMemory
997617LuvidiBigger segments (IZhO19_segments)C++17
13 / 100
2 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve() { int n; cin>>n; ll a[n+1],pre[n+1]; pre[0]=0; for(int i=0;i<n;i++){ cin>>a[i+1]; pre[i+1]=pre[i]+a[i+1]; } ll dp[n+1][n+1]; int idx[n+1]; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ dp[i][j]=1e18; } idx[i]=1e9; } dp[0][0]=0; idx[0]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(idx[j-1]>=i)continue; int l=1,r=i-idx[j-1]; while(l<r){ int m=(l+r)/2; if(pre[i]-pre[i-m]>=dp[i-m][j-1])r=m; else l=m+1; } if(pre[i]-pre[i-l]>=dp[i-l][j-1]){ dp[i][j]=pre[i]-pre[i-l]; idx[j]=min(idx[j],i); } } } ll ans=0; for(int i=1;i<=n;i++){ if(dp[n][i]<1e18)ans=i; } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...