Submission #435188

# Submission time Handle Problem Language Result Execution time Memory
435188 2021-06-23T05:03:54 Z MinhQNgo Distributing Candies (IOI21_candies) C++17
3 / 100
127 ms 11996 KB
#include "candies.h"

#include <bits/stdc++.h>

using namespace std;

std::vector<int> sub1(std::vector<int> c, std::vector<int> l,
                        std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    for (int time = 0; time < q; time++) {
        int L = l[time], R = r[time], V = v[time];
        for (int i = L; i <= R; i++) {
            if (V > 0) s[i] = min(c[i], s[i] + V);
            else s[i] = max(0, s[i] + V);
        }
    }
    return s;
}

std::vector<int> sub2(std::vector<int> c, std::vector<int> l,
                        std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    vector<int> p(n + 1, 0);
    for (int time = 0; time < q; time++) {
        int L = l[time], R = r[time], V = v[time];
        p[L] += V;
        p[R + 1] -= V;
    }
    for (int i = 1; i <= n; i++) p[i] += p[i - 1];
    for (int i = 0; i < n; i++) s[i] = min(c[i], s[i] + p[i]);
    return s;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    if (n <= 2000 && q <= 2000) {
        s = sub1(c, l, r, v);
    }
    else {
        s = sub2(c, l, r, v);
    }
    return s;
}
# 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 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 9 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 11996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 204 KB Output is correct
2 Incorrect 60 ms 7388 KB Output isn't correct
3 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 64 ms 7364 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 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 9 ms 332 KB Output is correct
6 Incorrect 127 ms 11996 KB Output isn't correct
7 Halted 0 ms 0 KB -