Submission #593055

# Submission time Handle Problem Language Result Execution time Memory
593055 2022-07-10T10:03:06 Z Vanilla Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 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, {1e18, -1}), mx (m + 2, {-1e18, -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 <int64> 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;
}

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:61:12: error: could not convert 'rs' from 'vector<long long int>' to 'vector<int>'
   61 |     return rs;
      |            ^~
      |            |
      |            vector<long long int>