Submission #883536

# Submission time Handle Problem Language Result Execution time Memory
883536 2023-12-05T11:47:22 Z nguyentunglam Distributing Candies (IOI21_candies) C++17
3 / 100
4244 ms 2097152 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 1e5 + 10;
vector<long long> event[N];

vector<int> distribute_candies (vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    vector<int> p;

    int n = c.size();

    l.insert(l.begin(), 0);
    l.insert(l.begin(), 0);

    r.insert(r.begin(), n - 1);
    r.insert(r.begin(), n - 1);

    v.insert(v.begin(), -2e9);
    v.insert(v.begin(), 2e9);

//     for(int i = 0; i < n; i++) {
//      event[i].push_back(2e9);
//      event[i].push_back(-2e9);
//    }

    for(int i = 0; i < v.size(); i++)
    {
        for(int j = l[i]; j <= r[i]; j++)
        {
            event[j].push_back(v[i]);
        }
    }

    for(int i = 0; i < n; i++)
    {
        long long sum = 0, border = 0;

        vector<long long> pref;

        for(long long &j : event[i]) {
            sum += j;
            pref.push_back(sum);
        }

        long long mx = -1e18, mn = 1e18;

        for(int j = pref.size() - 1; j >= 0; j--)
        {
            if (pref[j] < mn && mx - pref[j] > c[i]) {
              border = mx - c[i];
              break;
            }

            if (pref[j] > mx && pref[j] - mn > c[i]) {
              border = mn;
              break;
            }

            mn = min(mn, pref[j]);

            mx = max(mx, pref[j]);
        }

        p.push_back(sum - border);
    }

    return p;
}

#ifdef ngu
int32_t main() {

    freopen ("task.inp", "r", stdin);
    freopen ("task.out", "w", stdout);

    int n; cin >> n;

    vector<int> c(n);


    for(int i = 0; i < n; i++) cin >> c[i];

    int q; cin >> q;

    vector<int> l(q), r(q), v(q);

    for(int i = 0; i < q; i++) cin >> l[i] >> r[i] >> v[i];

    vector<int> ans = distribute_candies(c, l, r, v);

    for(int &j : ans) cout << j << " ";
}
#endif // ngu

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < v.size(); i++)
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 3592 KB Output is correct
5 Correct 21 ms 16364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 76 ms 24356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 2498 ms 1360748 KB Output is correct
3 Runtime error 27 ms 16976 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Runtime error 4244 ms 2097152 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 3592 KB Output is correct
5 Correct 21 ms 16364 KB Output is correct
6 Runtime error 76 ms 24356 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -