Submission #593054

# Submission time Handle Problem Language Result Execution time Memory
593054 2022-07-10T10:02:25 Z Vanilla Distributing Candies (IOI21_candies) C++17
0 / 100
107 ms 15148 KB
#include <bits/stdc++.h>
#include "candies.h"
typedef long long int64;
using namespace std;

// int64 find (int n, int64 c, vector <int64> &mx, vector <int64> &mn) {
//     int l = 1, r = n-1;
// }

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size();
    int m = v.size();
    v.insert(v.begin(), -1);
    vector <int64> pref (m + 2);
    vector <pair <int64, int64> >  mn (m + 2, {1e9, -1}), mx (m + 2, {-1e9, -1});
    for (int i = 1; i <= m; i++){
        pref[i] = pref[i-1] + v[i];
    }
    for (int i = m; i >= 1; i--){
        mx[i] = mx[i + 1], mn[i] = mn[i + 1];
        if (pref[i] > mx[i].first) {
            mx[i] = {pref[i], i};
        }
        if (pref[i] < mn[i].first) {
            mn[i] = {pref[i], i};
        }
    }
    // for (int i = 1; i <= m; i++){
    //     cout << pref[i] << " ";
    // }
    // cout << "\n";
    // for (int i = 1; i <= m; i++){
    //     cout << mn[i].first << " ";
    // }
    // cout << "\n";
    // for (int i = 1; i <= m; i++){
    //     cout << mx[i].first << " ";
    // }
    // cout << "\n";
    vector <int> rs (n);
    for (int i = 0; i < n; i++){
        int l = 1, r = m, f = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (mx[mid].first - mn[mid].first >= c[i]) {
                f = mid;
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }
        // cout << c[i] << " " << f << "\n";
        if (f == -1) rs[i] = pref[m];
        else {
            if (mn[f].second > mx[f].second) rs[i] = pref[m] - pref[mn[f].second];
            else rs[i] = c[i] + pref[m] - pref[mx[f].second];
        }

    }
    return rs;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 15148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 51 ms 12852 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -