Submission #957778

# Submission time Handle Problem Language Result Execution time Memory
957778 2024-04-04T10:13:14 Z I_am_Polish_Girl Bigger segments (IZhO19_segments) C++14
0 / 100
1 ms 348 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>

using namespace std;

#define int long long

int log_ = 10;
int inf = 1000000000000000000;
int mod = 998244353;




signed main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector <int> a(n);
    vector <int> pref(n);

    vector <int> dp(n);
    vector <int> col(n);

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

        pr += a[i];

        pref[i] = pr;

        dp[i] = pref[i];
        col[i] = 1;
    }

    pref.push_back(inf);

    for (int i = 0; i < n; i++)
    {
        int x = pref[i];

        int ind = lower_bound(pref.begin(), pref.end(), x + dp[i]) - pref.begin();

        if (ind == n)
            continue;

        if (dp[ind] > (pref[ind] - pref[i]))
            dp[ind] = (pref[ind] - pref[i]);

        if (dp[ind] == (pref[ind] - pref[i]))
            col[ind] = max(col[ind], col[i] + 1);
    }

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