Submission #1062517

# Submission time Handle Problem Language Result Execution time Memory
1062517 2024-08-17T08:11:34 Z j_vdd16 Distributing Candies (IOI21_candies) C++17
0 / 100
80 ms 12008 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, vs[0]);
    vector<ll> sufMax(q), sufMin(q);

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

        cumul[i] = cumul[i - 1] + v;
    }

    sufMax.back() = cumul.back();
    sufMin.back() = cumul.back();
    for (int i = q - 2; i >= 0; i--) {
        sufMin[i] = min(sufMin[i + 1], cumul[i]);
        sufMax[i] = max(sufMax[i + 1], cumul[i]);
    }

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

            ll intermediate = cumul[m];
            intermediate = min(intermediate, (ll)c[i]);
            intermediate = max(intermediate, (ll)0);

            //ll diff = sufMax[m] - sufMin[m];
            ll val = intermediate + cumul.back() - cumul[m];
            if (0 <= val && val <= c[i]) {
                r = m;
            }
            else { 
                l = m + 1;
            }
        }

        ll intermediate = cumul[l];
        intermediate = min(intermediate, (ll)c[i]);
        intermediate = max(intermediate, (ll)0);

        s[i] = intermediate + cumul.back() - cumul[l];
        //s[i] = min(s[i], c[i]);
        //s[i] = max(s[i], 0);
    }

    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 80 ms 12008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -