Submission #1067381

# Submission time Handle Problem Language Result Execution time Memory
1067381 2024-08-20T16:06:37 Z golf Distributing Candies (IOI21_candies) C++17
3 / 100
65 ms 10580 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> distribute_candies(
    vector<int> c, vector<int> l, 
    vector<int> r, vector<int> v
) {
    int n = c.size();
    int q = v.size();

    if (q <= 2000 && n <= 2000) {
        vector<int> s(n);

        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                s[j] = max(min(s[j] + v[i], c[j]), 0);
            }
        }

        return s;
    }

    bool pos = true;
    for (int i = 0; i < n; i++) {
        if (c[i] < 0) {
            pos = false;
            break;
        }
    }

    if (pos) {
        // difference array
        vector<long long> d(n + 1);

        for (int i = 0; i < q; i++) {
            d[l[i]] += v[i];
            d[r[i] + 1] -= v[i];
        }

        vector<long long> s(n);
        s[0] = d[0];
        for (int i = 1; i < n; i++) {
            s[i] = min(s[i - 1] + d[i], (long long)c[i]);
        }

        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            res[i] = s[i];
        }
        return res;
    }

    vector<int> s(n, 0);
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 10580 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 Incorrect 33 ms 4952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 29 ms 5112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Incorrect 65 ms 10580 KB Output isn't correct
7 Halted 0 ms 0 KB -