Submission #570923

# Submission time Handle Problem Language Result Execution time Memory
570923 2022-05-31T14:29:53 Z sff_user Distributing Candies (IOI21_candies) C++17
0 / 100
5000 ms 17580 KB
#include "candies.h"
#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();
    int yes=1;
    for(int i = 0 ; i < q ; i++) if(v[i] < 0) yes=0;
    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(n);
        for(int i = 0 ;i < n ; i++) not_F[i] = 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;
}

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:26:43: warning: 'mid2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |             int li=0,ri=not_F.size(),mid1,mid2;
      |                                           ^~~~
candies.cpp:26:38: warning: 'mid1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |             int li=0,ri=not_F.size(),mid1,mid2;
      |                                      ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1042 ms 17580 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 183 ms 6160 KB Output is correct
3 Correct 189 ms 5080 KB Output is correct
4 Execution timed out 5016 ms 8548 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 428 ms 6268 KB Output is correct
4 Correct 408 ms 3988 KB Output is correct
5 Execution timed out 5020 ms 8524 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -