Submission #334924

# Submission time Handle Problem Language Result Execution time Memory
334924 2020-12-10T09:41:50 Z Trickster Bigger segments (IZhO19_segments) C++14
0 / 100
1 ms 384 KB
//Suleyman Atayew
 
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
 
#define N 500010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) (ll)(a.size())
ll bigmod(ll a, ll b) { if(b==0)return 1; ll ret = bigmod(a, b/2); return ret * ret % mod * (b%2 ? a : 1) % mod; }

using namespace std;

ll n;
ll v[N];
ll dp[N];

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    cin >> n;

    for(ll i = 1; i <= n; i++) cin >> v[i], v[i] += v[i-1];

    priority_queue <pii> Q;

    Q.push({0, 0});
    for(ll i = 1; i <= n; i++) {
        ll in = 0;

        while(!Q.empty() && -Q.top().ff <= v[i]) {
            if(dp[Q.top().ss] > dp[in] || (dp[Q.top().ss] == dp[in] && in < Q.top().ss)) in = Q.top().ss;

            Q.pop();
        }

        dp[i] = dp[in]+1;
        Q.push({v[in]-v[i]*2, i});
    }

    cout << dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -