답안 #570930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570930 2022-05-31T14:44:42 Z sff_user 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 17024 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;
    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]);
            }
        }
    }
    else{
        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(),mid1,mid2;
            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();
            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<<" ";
}*/

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:25:43: warning: 'mid2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |             int li=0,ri=not_F.size(),mid1,mid2;
      |                                           ^~~~
candies.cpp:25:38: warning: 'mid1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |             int li=0,ri=not_F.size(),mid1,mid2;
      |                                      ^~~~
# 결과 실행 시간 메모리 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 995 ms 17024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 166 ms 5064 KB Output is correct
3 Correct 199 ms 3752 KB Output is correct
4 Execution timed out 5006 ms 7364 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 419 ms 5056 KB Output is correct
4 Correct 444 ms 2804 KB Output is correct
5 Execution timed out 5051 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 -