Submission #443501

# Submission time Handle Problem Language Result Execution time Memory
443501 2021-07-10T16:00:24 Z mjhmjh1104 Distributing Candies (IOI21_candies) C++17
0 / 100
133 ms 7236 KB
#include "candies.h"
#include <vector>
#include <algorithm>
using namespace std;

struct Move {
    long long o;
    long long n;
    int c;
};

vector<Move> V;
long long cnt;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    cnt = 0; V.clear();
    int n = (int)c.size(), q = (int)v.size();
    long long globalMin = 0, globalMax = 0;
    vector<int> s(n);
    for (int t = 0; t < q; t++) {
        if (v[t] > 0) {
            int curr = v[t];
            while (!V.empty()) {
                if (V.back().n > V.back().o) {
                    v[t] = cnt + v[t] - V.back().o;
                    cnt = V.back().o;
                    V.pop_back();
                } else if (V.back().c <= curr) V.pop_back();
                else break;
            }
        } else {
            int curr = -v[t];
            while (!V.empty()) {
                if (V.back().n < V.back().o) {
                    v[t] = cnt + v[t] - V.back().o;
                    cnt = V.back().o;
                    V.pop_back();
                } else if (V.back().c <= curr) V.pop_back();
                else break;
            }
        }
        V.push_back(Move{ cnt, cnt + v[t], v[t] > 0 ? v[t] : -v[t] });
        cnt += v[t];
        globalMin = min(globalMin, cnt), globalMax = max(globalMax, cnt);
    }
    //for (auto &i: V) printf("%lld %lld %d\n", i.o, i.n, i.c);
    for (int i = 0; i < n; i++) {
        long long l = globalMin, r = globalMax;
        if (V.front().c >= c[i]) {
            Move x = *(upper_bound(V.begin(), V.end(), Move{ 0LL, 0LL, c[i] }, [](const Move &a, const Move &b) {
                return a.c > b.c;
            }) - 1);
            if (x.o > x.n) l = x.n, r = l + c[i];
            else r = x.n, l = r - c[i];
        //printf("%lld %lld %d\n", x.o, x.n, x.c);
        }
        //printf("! %lld %lld\n", l, r);
        if (l < 0) s[i] = cnt - l;
        else if (r > c[i]) s[i] = cnt - r + c[i];
        else s[i] = cnt;
    }
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 133 ms 7236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 63 ms 5844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -