Submission #259875

# Submission time Handle Problem Language Result Execution time Memory
259875 2020-08-08T18:16:11 Z Osama_Alkhodairy Bigger segments (IZhO19_segments) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 500001;

int n, sum[N];
vector <int> a;

int get_sum(int l, int r){
    if(r < l) return 0;
    return sum[r] - (l == 0 ? 0 : sum[l - 1]);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    if(n == 1) finish(1);
    for(int i = 0 ; i < n ; i++){
        if(i > 0) sum[i] = sum[i - 1];
        sum[i] += a[i];
    }
    vector <pair <int, int> > ans;
    ans.push_back(make_pair(0, 0));
    ans.push_back(make_pair(1, 1));
    for(int i = 2 ; i < n ; i++){
        auto &g = ans[ans.size() - 2];
        auto &h = ans[ans.size() - 1];
        if(get_sum(g.first, g.second) > get_sum(h.first, h.second)){
            ans.back().second++;
        }
        else{
            while(get_sum(g.first, g.second + 1) <= get_sum(h.first + 1, h.second)){
                g.second++;
                h.first++;
            }
            ans.push_back(make_pair(i, i));
        }
    }
    auto &g = ans[ans.size() - 2];
    auto &h = ans[ans.size() - 1];
    if(get_sum(g.first, g.second) > get_sum(h.first, h.second)) ans.pop_back();
    cout << ans.size() << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -