Submission #834752

# Submission time Handle Problem Language Result Execution time Memory
834752 2023-08-22T18:14:36 Z JakobZorz Distributing Candies (IOI21_candies) C++17
3 / 100
5000 ms 20580 KB
#include"candies.h"
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int n,days;

vector<ll>vec;
void tree_init(){
    vec.resize(days);
}

void tree_add(int pos,int val){
    for(int i=pos;i<days;i++)
        vec[i]+=val;
}

int tree_get(int bound){
    /*for(ll i:vec)
        cout<<i<<" ";
    cout<<endl;*/
    
    int min_i=days-1,max_i=days-1;
    for(int i=days-1;i>=0;i--){
        if(vec[i]<vec[min_i])
            min_i=i;
        if(vec[i]>vec[max_i])
            max_i=i;
        if(vec[max_i]-vec[min_i]>=bound){
            if(max_i==i){
                return vec[days-1]-vec[min_i];
            }else{
                return bound-(vec[max_i]-vec[days-1]);
            }
        }
    }
    
    return vec[days-1]-vec[min_i];
}

vector<int>distribute_candies(vector<int>c,vector<int>l,vector<int>r,vector<int>v){
    n=(int)c.size();
    days=(int)v.size()+1;
    vector<vector<pair<int,int>>>events;
    events.resize(n+1);
    
    for(int i=0;i<days-1;i++){
        events[l[i]].push_back({i+1,v[i]});
        events[r[i]+1].push_back({i+1,-v[i]});
    }
    
    vector<int>s(n);
    tree_init();
    
    for(int i=0;i<n;i++){
        for(auto event:events[i])
            tree_add(event.first,event.second);
        s[i]=tree_get(c[i]);
    }
    
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5050 ms 20580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5020 ms 11652 KB Time limit exceeded
3 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 Execution timed out 5083 ms 10568 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Execution timed out 5050 ms 20580 KB Time limit exceeded
7 Halted 0 ms 0 KB -