답안 #570933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570933 2022-05-31T14:49:53 Z sff_user 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 17076 KB
#include <vector>
#include<bits/stdc++.h>

using namespace std;

vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n,0);
    int q=l.size();
    bool yes=true;
    for(int i = 0 ; i < q ; i++){
        if(v[i]<0){
            yes=false;break;
        }
    }
    if(!yes){
        for(int i = 0 ; i < q ; i++){
            for(int j = l[i] ; j <= r[i] ; j ++){
                if(v[i] > 0) s[j] = min(c[j],s[j]+v[i]);
                else         s[j] = max(0,s[j]+v[i]);
            }
        }
        return s;
    }
        vector<int> not_F;
        for(int i = 0 ;i < n ; i++) not_F.push_back(i);
        for(int i = 0 ; i < q ; i++){
            int li=0,ri=not_F.size()-1,mid1=l[i],mid2=r[i];
            while(li <= ri){
                mid1=(ri+li)/2;
                if(not_F[mid1] >= l[i]){
                    ri= mid1-1;
                }
                else{
                    li=mid1+1;
                }
            }
            li=0,ri=not_F.size()-1;
            while(li <= ri){
                mid2=(ri+li)/2;
                if(not_F[mid2] <= r[i]){
                    li= mid2+1;
                }
                else{
                    ri=mid2-1;
                }
            }
            for(int j = mid1;j<=mid2;j++){
                s[j] = min(c[j],s[j]+v[i]);
                if(s[j]==c[j]) not_F.erase(not_F.begin()+j);
            }
        }
    

    return s;
}


/*vector<int> distribute_candies1(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n,0);
    int q=l.size();
    
        for(int i = 0 ; i < q ; i++){
            for(int j = l[i] ; j <= r[i] ; j ++){
                if(v[i] > 0) s[j] = min(c[j],s[j]+v[i]);
                else         s[j] = max(0,s[j]+v[i]);
            }
        }
    return s;

}
int main(){
    int n,q;
    cin >> n >> q;
    vector<int>c(n),l(q),r(q),v(q);
    for(int i = 0 ; i < n ; i++) cin >> c[i];
    for(int i = 0 ; i < q ; i++) cin >> l[i];
    for(int i = 0 ; i < q ; i++) cin >> r[i];
    for(int i = 0 ; i < q ; i++) cin >> v[i];
    vector<int> cc = distribute_candies2(c,l,r,v);
    cout <<"daz"<<endl;
    for(int c:cc)cout<<c<<" ";
    cout << endl;
    vector<int> cc2 = distribute_candies1(c,l,r,v);
    for(int c:cc2)cout<<c<<" ";
}*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 980 ms 17076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 185 ms 5036 KB Output is correct
3 Correct 171 ms 3824 KB Output is correct
4 Execution timed out 5073 ms 7272 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 471 ms 5024 KB Output is correct
4 Correct 422 ms 2804 KB Output is correct
5 Execution timed out 5072 ms 7280 KB Time limit exceeded
6 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 -