답안 #588133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588133 2022-07-02T17:57:12 Z sofijavelkovska 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 25320 KB
#include <bits/stdc++.h>
using namespace std;

void update(int x, int l, int r, int segmenttree[], int ls, int rs, int vs)
{
    if (l>rs || r<ls)
        return;
    if (l>=ls && r<=rs)
    {
        segmenttree[x]=segmenttree[x]+vs;
        return;
    }
    if (r-l==1)
        return;
    int m=(l+r)/2;
    update(2*x+1, l, m, segmenttree, ls, rs, vs);
    update(2*x+2, m, r, segmenttree, ls, rs, vs);

    return;
}

void find(int x, int l, int r, int segmenttree[], int index, vector<int> &s, vector<int> c)
{
    if (l>index || r<=index)
        return;
    s[index]=min(s[index]+segmenttree[x], c[index]);
    if (r-l==1)
        return;
    int m=(l+r)/2;
    find(2*x+1, l, m, segmenttree, index, s, c);
    find(2*x+2, m, r, segmenttree, index, s, c);

    return;
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
    int n=c.size();
    int q=l.size();
    if (n<=2000 && q<=2000)
    {
        vector<int> s(n);
        for (int i=0; i<n; i++)
            s[i]=0;
        for (int i=0; i<q; i++)
        {
            if (v[i]>0)
                for (int j=l[i]; j<=r[i]; j++)
                    s[j]=min(s[j]+v[i], c[j]);
            else
                for (int j=l[i]; j<=r[i]; j++)
                    s[j]=max(s[j]+v[i], 0);
        }
        return s;
    }
    int t=0;
    for (auto x : v)
        if (x>0)
            t=t+1;
    if (t==q)
    {
        int m=pow(2, 19);
        int segmenttree[m]={0};
        for (int i=0; i<q; i++)
            update(0, 0, n, segmenttree, l[i], r[i]+1, v[i]);
        vector<int> s(n);
        for (int i=0; i<n; i++)
            s[i]=0;
        for (int i=0; i<n; i++)
            find(0, 0, n, segmenttree, i, s, c);
        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:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5015 ms 25320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 107 ms 8220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Incorrect 102 ms 8276 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Execution timed out 5015 ms 25320 KB Time limit exceeded
7 Halted 0 ms 0 KB -