Submission #1001663

# Submission time Handle Problem Language Result Execution time Memory
1001663 2024-06-19T06:51:07 Z Andrey Distributing Candies (IOI21_candies) C++17
29 / 100
127 ms 26412 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) {
    long long n = c.size(),q = v.size();
    vector<long long> su(q+1);
    vector<pair<long long,long long>> sm(q+2);
    vector<pair<long long,long long>> big(q+2);
    sm[q] = {0,q};
    big[q] = {0,q};
    sm[q+1] = {0,q+1};
    big[q+1] = {0,q+1};
    for(long long i = q-1; i >= 0; i--) {
        su[i] = v[i];
        su[i]+=su[i+1];
        if(su[i] < sm[i+1].first) {
            sm[i] = {su[i],i};
        }
        else {
            sm[i] = sm[i+1];
        }
        if(su[i] > big[i+1].first) {
            big[i] = {su[i],i};
        }
        else {
            big[i] = big[i+1];
        }
    }
    vector<pair<long long,long long>> haha(n);
    for(long long i = 0; i < n; i++) {
        haha.push_back({c[i],i});
    }
    sort(haha.begin(),haha.end());
    reverse(haha.begin(),haha.end());
    long long p = -1;
    bool yeah = true;
    vector<int> ans(n);
    for(long long i = 0; i < n; i++) {
        while(p+1 < q) {
            if(yeah) {
                if(su[p+1]-big[p+2].first <= 0) {
                    p = big[p+2].second-1;
                    yeah = true;
                }
                else if(su[p+1]-sm[p+2].first >= haha[i].first) {
                    p = sm[p+2].second-1;
                    yeah = false;
                }
                else {
                    break;
                }
            }
            else {
                if(su[p+1]-big[p+2].first <= -haha[i].first) {
                    p = big[p+2].second-1;
                    yeah = true;
                }
                else if(su[p+1]-sm[p+2].first >= 0){
                    p = sm[p+2].second-1;
                    yeah = false;
                }
                else {
                    break;
                }
            }
        }
        if(yeah) {
            ans[haha[i].second] = su[p+1];
        }
        else {
            ans[haha[i].second] = haha[i].first+su[p+1];
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 21388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 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 Correct 0 ms 348 KB Output is correct
3 Correct 66 ms 15452 KB Output is correct
4 Correct 54 ms 10368 KB Output is correct
5 Correct 87 ms 24860 KB Output is correct
6 Correct 127 ms 25780 KB Output is correct
7 Correct 99 ms 26112 KB Output is correct
8 Correct 86 ms 24856 KB Output is correct
9 Correct 95 ms 26412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -