답안 #834734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834734 2023-08-22T18:02:10 Z JakobZorz 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 20584 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];
}

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;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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5048 ms 20584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -