Submission #161074

# Submission time Handle Problem Language Result Execution time Memory
161074 2019-10-31T13:21:06 Z stoyan_malinin Bigger segments (IZhO19_segments) C++14
0 / 100
2 ms 376 KB
#include<iostream>
#include<vector>

using namespace std;

const int MAXN = 5e5 + 5;

int n;
long long a[MAXN];

struct segment
{
    int l, r;
    long long sum;

    segment(){}
    segment(int l, int r, long long sum)
    {
        this->l = l;
        this->r = r;
        this->sum = sum;
    }
};

vector <segment> v;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int answer = 0;

    cin >> n;
    for(int i = 0;i<n;i++)
    {
        cin >> a[i];
    }

    v.push_back(segment(0, 0, a[0]));

    segment curr = segment(1, 0, 0);
    for(int i = 1;i<n;i++)
    {
        curr.r++;
        curr.sum += a[i];

        for(int j = v.size()-1;j>=1;j--)
        {
            while(v[j].sum - a[ v[j].l ] >= v[j-1].sum + a[ v[j].l ])
            {
                v[j].sum -= a[ v[j].l ];
                v[j-1].sum += a[ v[j].l ];

                v[j].l++;
                v[j-1].r++;
            }
        }
        for(int j = 1;j<v.size();j++)
        {
            while(v[j].sum - a[ v[j].l ] >= v[j-1].sum + a[ v[j].l ])
            {
                v[j].sum -= a[ v[j].l ];
                v[j-1].sum += a[ v[j].l ];

                v[j].l++;
                v[j-1].r++;
            }
        }

        if(curr.sum >= v.back().sum)
        {
            v.push_back(curr);
            curr = segment(i+1, i, 0);
        }
    }

    cout << v.size() << '\n';
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1;j<v.size();j++)
                       ~^~~~~~~~~
segments.cpp:32:9: warning: unused variable 'answer' [-Wunused-variable]
     int answer = 0;
         ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -