Submission #1160543

#TimeUsernameProblemLanguageResultExecution timeMemory
1160543lumaticssBigger segments (IZhO19_segments)C++20
13 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,sse4a,abm,mmx,avx,avx2,fma,popcnt,tune=native")

#define int long long
#define qweqdasd ios_base::sync_with_stdio(0), cin.tie(0)
#define pb push_back
#define st first
#define nd second
#define watch(x) (cout << #x << " == " << x << '\n')

mt19937_64 rng(147098291);
random_device rd;
mt19937_64 mersenne(rd());

const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const int mod2 = (119 << 23) + 1; // 998244353
const int inf = 1e18;
const double eps = 1e-7;
const int block = 350;
const int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
const int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

int a[maxn], pref[maxn];

int Sum(int l, int r)
{
    return pref[r] - pref[l - 1];
}

void solve()
{
    int n;
    cin >> n;
    pref[0] = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    int sum[n + 1];
    vector<int> dp(n + 1, 0);
    dp[0] = sum[0] = 0;
    dp[1] = 1;
    sum[1] = a[1];
    for (int i = 2; i <= n; ++i) {
        int low = 1, high = i - 1;
        int j = 0;
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (sum[mid] <= Sum(mid + 1, i)) {
                j = mid;
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        // for (int j = 1; j <= i - 1; ++j) {
        //     if (sum[j] <= Sum(j + 1, i)) {
        //         dp[i] = max(dp[i], dp[j] + 1);
        //     }
        // }
        dp[i] = dp[j] + 1;
        sum[i] = Sum(j + 1, i);
    }
    cout << dp[n];
}

int32_t main()
{
    qweqdasd;
    int tests = 1;
    // cin >> tests;
    for (int i = 1; i <= tests; ++i) {
        // cout << "Case " << i << ":\n";
        solve();
    }
#ifdef LOCAL
    cerr << '\n'
         << "fnshd in " << clock() * 1.0 / CLOCKS_PER_SEC << " s\n";
#endif
}
/**
 *
 */
#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...