제출 #1172048

#제출 시각아이디문제언어결과실행 시간메모리
1172048AtabayRajabliBigger segments (IZhO19_segments)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;

const int sz = 3e3 + 1, inf = 1e18;
int n, a[sz], dp[sz][sz];

signed main()
{                                                                  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) dp[i][j] = 1;
    for(int i = 1; i < n; i++)
    {
        for(int j = i; j < n; j++)
        {
            int l = j + 1, r = n;
            while(l <= r)
            {
                int mid = (l + r) >> 1;
                if(a[mid] - a[j] >= a[j] - a[i - 1]) 
                    r = mid - 1;
                else 
                    l = mid + 1;
            }
            int nxt = r + 1;
            if(j < nxt && nxt <= n) dp[j + 1][nxt] = max(dp[j + 1][nxt], dp[i][j] + 1);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans = max(ans, dp[i][n]);
    }
    cout << ans;
}
#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...