Submission #522712

# Submission time Handle Problem Language Result Execution time Memory
522712 2022-02-05T13:44:03 Z InternetPerson10 Distributing Candies (IOI21_candies) C++17
40 / 100
124 ms 17516 KB
#include "candies.h"
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const ll BIG = 123456789123456789;

vector<int> distribute_candies(vector<int> cInt, vector<int> lInt, vector<int> rInt, vector<int> vInt) {
    int n = cInt.size();
    int q = vInt.size();
    vector<ll> s(n+1), c(n), l(q), r(q), v(q);
    for(int i = 0; i < n; i++) {
        c[i] = cInt[i];
    }
    for(int i = 0; i < q; i++) {
        l[i] = lInt[i];
        r[i] = rInt[i];
        v[i] = vInt[i];
    }
    bool subtask2 = true, subtask3 = true, subtask4 = true;
    for(int i = 1; i < n; i++) {
        if(c[i] != c[i-1]) subtask3 = false;
    }
    for(int i = 0; i < q; i++) {
        if(v[i] < 0) subtask2 = false;
        if(r[i] - l[i] != n-1) subtask4 = false;
    }
    if(n <= 2000 && q <= 2000) { // Subtask 1
        for(int i = 0; i < q; i++) {
            for(int j = l[i]; j <= r[i]; j++) {
                s[j] += v[i];
                s[j] = max(s[j], 0LL);
                s[j] = min(s[j], c[j]);
            }
        }
    }
    else if(subtask2) {
        for(int i = 0; i < q; i++) {
            s[l[i]] += v[i];
            s[r[i]+1] -= v[i];
        }
        for(int i = 1; i < n; i++) {
            s[i] += s[i-1];
        }
        for(int i = 0; i < n; i++) {
            s[i] = min(s[i], c[i]);
        }
    }
    else if(subtask3) {

    }
    else if(subtask4) {
        vector<ll> qs;
        qs.push_back(-BIG);
        auto sameSign = [&]() {
            ll x = qs[qs.size() - 2];
            ll y = qs[qs.size() - 1];
            return ((x >= 0 && y >= 0) || (x <= 0 && y <= 0));
        };
        auto decreasingOrder = [&]() {
            ll x = qs[qs.size() - 2];
            ll y = qs[qs.size() - 1];
            return (abs(x) > abs(y));
        };
        for(ll g : v) {
            qs.push_back(g);
            while(qs.size() > 1) {
                if(sameSign() || !decreasingOrder()) {
                    ll last = qs.back(); qs.pop_back();
                    qs[qs.size() - 1] += last;
                }
                else break;
            }
        }
        if(qs.size()%2) qs.push_back(0);
        qs.push_back(0);
        reverse(qs.begin(), qs.end());
        for(ll &g : qs) g = abs(g);
        vector<pair<ll, int>> caps(n);
        for(int i = 0; i < n; i++) caps[i] = {c[i], i};
        sort(caps.begin(), caps.end());
        ll currCount = 0;
        int j = 0;
        for(int i = 1; i < qs.size(); i++) {
            if(i%2 == 0) {
                currCount += (qs[i-1] - qs[i-2]);
            }
            while(j != n) {
                if(caps[j].first > qs[i]) break;
                if(i%2) s[caps[j].second] = currCount + (caps[j].first - qs[i-1]);
                else s[caps[j].second] = currCount;
                j++;
            }
        }
    }
    else {

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

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:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int i = 1; i < qs.size(); i++) {
      |                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 15156 KB Output is correct
2 Correct 106 ms 15076 KB Output is correct
3 Correct 99 ms 15156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 56 ms 9684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 50 ms 9668 KB Output is correct
4 Correct 60 ms 8140 KB Output is correct
5 Correct 115 ms 17516 KB Output is correct
6 Correct 113 ms 17476 KB Output is correct
7 Correct 124 ms 17476 KB Output is correct
8 Correct 111 ms 17460 KB Output is correct
9 Correct 102 ms 15156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 109 ms 15156 KB Output is correct
7 Correct 106 ms 15076 KB Output is correct
8 Correct 99 ms 15156 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 56 ms 9684 KB Output isn't correct
11 Halted 0 ms 0 KB -