Submission #341160

# Submission time Handle Problem Language Result Execution time Memory
341160 2020-12-29T04:41:44 Z Dilshod_Imomov Bigger segments (IZhO19_segments) C++17
0 / 100
1 ms 512 KB
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
 
using namespace std;
 
const int N = 5e5 + 7;
const int mod = 1e9 + 7;

int a[N], sum[N], dp[N], ind[N];

int32_t main() {
    speed; 
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for ( int i = 1; i <= n; i++ ) {
        ind[i] = max( ind[i - 1], ind[i] );
        dp[i] = dp[ ind[i] ] + 1;
        int l = i + 1, r = n, ans = n + 1;
        while ( l <= r ) {
            int m = (l + r) / 2;
            if ( sum[m] - sum[i] >= sum[i] - sum[ ind[i] - 1 ] ) {
                ans = m;
                r = m - 1;
            }
            else {
                l = m + 1;
            }
        }
        ind[ans] = i;
    }
    cout << dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -