Submission #960949

# Submission time Handle Problem Language Result Execution time Memory
960949 2024-04-11T09:46:59 Z tudor_costin Cat Exercise (JOI23_ho_t4) C++11
21 / 100
75 ms 15444 KB
#include <iostream>

using namespace std;
const int Nmax=2e5+5;
int aint[4*Nmax];
int a[Nmax];
int pos[Nmax];
int n;
int sol=0;
void build(int nod,int l,int r)
{
    if(l==r)
    {
        aint[nod]=a[l];
        return;
    }
    int mid=(l+r)/2;
    build(2*nod,l,mid);
    build(2*nod+1,mid+1,r);
    aint[nod]=max(aint[2*nod],aint[2*nod+1]);
    return;
}
int query(int nod,int l,int r,int st,int dr)
{
    if(st<=l && r<=dr) return aint[nod];
    int mid=(l+r)/2;
    if(dr<=mid) return query(2*nod,l,mid,st,dr);
    if(mid<st) return query(2*nod+1,mid+1,r,st,dr);
    return max(query(2*nod,l,mid,st,mid),query(2*nod+1,mid+1,r,mid+1,dr));
}
int solve(int l,int r,int poz)
{
    int op1=0,op2=0;
    ///in stanga
    if(poz>l)
    {
        int newr=poz-1;
        int pozst=pos[query(1,1,n,l,newr)];
        op1=poz-pozst;
        op1+=solve(l,newr,pozst);
    }
    ///in dreapta
     if(poz<r)
    {
        int newl=poz+1;
        int pozdr=pos[query(1,1,n,newl,r)];
        op2=pozdr-poz;
        op2+=solve(newl,r,pozdr);
    }
    return max(op1,op2);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pos[a[i]]=i;
    }
    build(1,1,n);
    int pozi=pos[query(1,1,n,1,n)];
    cout<<solve(1,n,pozi)<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Incorrect 2 ms 2396 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Incorrect 75 ms 15444 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2488 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 3 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Incorrect 2 ms 2396 KB Output isn't correct
27 Halted 0 ms 0 KB -