Submission #443500

# Submission time Handle Problem Language Result Execution time Memory
443500 2021-07-10T15:53:42 Z mjhmjh1104 Distributing Candies (IOI21_candies) C++17
0 / 100
140 ms 7244 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();
    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];
    }
    //for (auto &i: V) printf("%lld %lld %d\n", i.o, i.n, i.c);
    for (int i = 0; i < n; i++) {
        Move x;
        if (V.front().c < c[i]) x = V.front();
        else x = *(upper_bound(V.begin(), V.end(), Move{ 0LL, 0LL, c[i] }, [](const Move &a, const Move &b) {
            return a.c > b.c;
        }) - 1);
        //printf("%lld %lld %d\n", x.o, x.n, x.c);
        long long l = 0, r = 0;
        if (x.o > x.n) l = x.n, r = l + c[i];
        else r = x.n, l = r - c[i];
        //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 0 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 140 ms 7244 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 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -