Submission #1062669

# Submission time Handle Problem Language Result Execution time Memory
1062669 2024-08-17T09:42:19 Z j_vdd16 Distributing Candies (IOI21_candies) C++17
29 / 100
83 ms 15300 KB
#include "candies.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define ll long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;


// struct SegTree {
//     int n, N;
//     vector<set<int>> tree;

//     SegTree(int _n) {
//         int n = _n;
//         int N = 1;
//         while (N < n) N *= 2;

//         tree.resize(2 * N);

//     }
// };

vi distribute_candies(vi c, vi ls, vi rs, vi vs) {
    int n = c.size();
    int q = ls.size();

    vector<ll> cumul(q + 1, 0);
    vector<pair<ll, int>> sufMax(q + 1), sufMin(q + 1);

    for (int i = 0; i < q; i++) {
        ll v = vs[i];

        cumul[i + 1] = cumul[i] + v;
        cumul[i + 1] = max((ll)0, cumul[i + 1]);
    }

    sufMax.back() = {cumul[q], q};
    sufMin.back() = {cumul[q], q};
    for (int i = q - 1; i >= 0; i--) {
        sufMin[i] = sufMin[i + 1];
        sufMax[i] = sufMax[i + 1];
        if (cumul[i] < sufMin[i + 1].first) {
            sufMin[i].first = cumul[i];
            sufMin[i].second = i;
        }
        if (cumul[i] > sufMax[i + 1].first) {
            sufMax[i].first = cumul[i];
            sufMax[i].second = i;
        }
    }

    vi s(n);
    loop(i, n) {
        int l = 0, r = q;
        while (l < r) {
            int m = (l + r + 1) / 2;

            ll diff = sufMax[m].first - sufMin[m].first;
            if (diff < c[i]) {
                r = m - 1;
            }
            else { 
                l = m;
            }
        }

        if (l == 0) {
            s[i] = cumul.back();
            continue;
        }

        int lastMin = sufMin[l].second;
        int lastMax = sufMax[l].second;
        if (lastMin >= lastMax) {
            l = lastMin;
            s[i] = 0;
        }
        else {
            l = lastMax;
            s[i] = c[i];
        }

        s[i] += cumul.back() - cumul[l];
    }

    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 15188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 33 ms 12880 KB Output is correct
4 Correct 43 ms 3000 KB Output is correct
5 Correct 71 ms 15084 KB Output is correct
6 Correct 79 ms 15080 KB Output is correct
7 Correct 74 ms 15300 KB Output is correct
8 Correct 66 ms 15100 KB Output is correct
9 Correct 68 ms 15100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -