Submission #1067906

# Submission time Handle Problem Language Result Execution time Memory
1067906 2024-08-21T05:27:47 Z Muhammad_Aneeq Meetings (IOI18_meetings) C++17
36 / 100
5500 ms 11724 KB
#include <vector>
using namespace std;
int const N=1e5+10;
struct node
{
    int msb=0,mp=0,ms=0;
    bool valid=0;
};
node St[4*N]={};
node comb(node a,node b)
{
    node c;
    c.valid=(a.valid&&b.valid);
    c.msb=max(a.msb,b.msb);
    if (a.ms&&b.mp)
        c.msb=max(c.msb,a.ms+b.mp);
    c.ms=b.ms;
    if (b.valid)
        c.ms=max(c.ms,a.ms+b.ms);
    c.mp=a.mp;
    if (a.valid)
        c.mp=max(c.mp,a.mp+b.mp);
    return c;
}
void update(int i,int r,int st,int en,int val)
{
    if (st==en)
    {
        if (val==1)
        {
            St[i].msb=St[i].ms=St[i].mp=St[i].valid=1;
        }
        return;
    }
    int mid=(st+en)/2;
    if (r<=mid)
        update(i*2,r,st,mid,val);
    else
        update(i*2+1,r,mid+1,en,val);
    St[i]=comb(St[i*2],St[i*2+1]);
}
node get(int i,int st,int en,int l,int r)
{
    if (st>=l&&en<=r)
        return St[i];
    if (st>r||en<l)
    {
        node c;
        c.valid=1;
        return c;
    }
    int mid=(st+en)/2;
    return comb(get(i*2,st,mid,l,r),get(i*2+1,mid+1,en,l,r));
}
vector<long long> minimum_costs(vector<int> H, vector<int> L,vector<int> R)
{
    int n=H.size();
    vector<long long>ans(L.size(),1e15);
    bool subt3=1;
    for (int i=0;i<n;i++)
        if (H[i]>2)
            subt3=0;
    if (subt3)
    { 
        for (int i=0;i<n;i++)
            update(1,i,0,n-1,H[i]);
        vector<long long>ans;
        for (int i=0;i<L.size();i++)
        {
            node z=get(1,0,n-1,L[i],R[i]);
            ans.push_back(2*(R[i]-L[i]+1)-z.msb);
        }
        return ans;
    }
    int val[n]={};
    long long pre[n+1]={};
    for (int i=0;i<n;i++)
    {
        int mx=H[i];
        val[i]=mx;
        for (int j=i-1;j>=0;j--)
        {
            mx=max(mx,H[j]);
            val[j]=mx;
        }
        mx=H[i];
        for (int j=i+1;j<n;j++)
        {
            mx=max(mx,H[j]);
            val[j]=mx;
        }
        for (int j=1;j<=n;j++)
            pre[j]=pre[j-1]+val[j-1];
        for (int j=0;j<L.size();j++)
        {
            if (i>=L[j]&&i<=R[j])
                ans[j]=min(ans[j],pre[R[j]+1]-pre[L[j]]);
        }
    }
    return ans;
}

Compilation message

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int i=0;i<L.size();i++)
      |                      ~^~~~~~~~~
meetings.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for (int j=0;j<L.size();j++)
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 13 ms 496 KB Output is correct
3 Correct 20 ms 344 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 12 ms 348 KB Output is correct
6 Correct 13 ms 344 KB Output is correct
7 Correct 13 ms 348 KB Output is correct
8 Correct 13 ms 348 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 13 ms 496 KB Output is correct
3 Correct 20 ms 344 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 12 ms 348 KB Output is correct
6 Correct 13 ms 344 KB Output is correct
7 Correct 13 ms 348 KB Output is correct
8 Correct 13 ms 348 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 63 ms 640 KB Output is correct
11 Correct 72 ms 604 KB Output is correct
12 Correct 63 ms 604 KB Output is correct
13 Correct 66 ms 600 KB Output is correct
14 Correct 65 ms 604 KB Output is correct
15 Correct 68 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 27 ms 2516 KB Output is correct
3 Correct 90 ms 11680 KB Output is correct
4 Correct 80 ms 11724 KB Output is correct
5 Correct 68 ms 11724 KB Output is correct
6 Correct 71 ms 9676 KB Output is correct
7 Correct 82 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 27 ms 2516 KB Output is correct
3 Correct 90 ms 11680 KB Output is correct
4 Correct 80 ms 11724 KB Output is correct
5 Correct 68 ms 11724 KB Output is correct
6 Correct 71 ms 9676 KB Output is correct
7 Correct 82 ms 11212 KB Output is correct
8 Execution timed out 5536 ms 6484 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 13 ms 496 KB Output is correct
3 Correct 20 ms 344 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 12 ms 348 KB Output is correct
6 Correct 13 ms 344 KB Output is correct
7 Correct 13 ms 348 KB Output is correct
8 Correct 13 ms 348 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 63 ms 640 KB Output is correct
11 Correct 72 ms 604 KB Output is correct
12 Correct 63 ms 604 KB Output is correct
13 Correct 66 ms 600 KB Output is correct
14 Correct 65 ms 604 KB Output is correct
15 Correct 68 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 27 ms 2516 KB Output is correct
18 Correct 90 ms 11680 KB Output is correct
19 Correct 80 ms 11724 KB Output is correct
20 Correct 68 ms 11724 KB Output is correct
21 Correct 71 ms 9676 KB Output is correct
22 Correct 82 ms 11212 KB Output is correct
23 Execution timed out 5536 ms 6484 KB Time limit exceeded
24 Halted 0 ms 0 KB -