Submission #1017792

# Submission time Handle Problem Language Result Execution time Memory
1017792 2024-07-09T10:14:58 Z lucri September (APIO24_september) C++17
100 / 100
299 ms 21964 KB
#include <bits/stdc++.h>
std::vector<std::vector<int>>a;
int pozmin[100010],pozmax[100010],aint[400010];
void update(int poz,int b,int e,int pozu,int val)
{
    if(b>pozu||pozu>e)
        return;
    aint[poz]=std::max(aint[poz],val);
    if(b==e)
        return;
    update(poz*2,b,(b+e)/2,pozu,val);
    update(poz*2+1,(b+e)/2+1,e,pozu,val);
}
int maxim(int poz,int b,int e,int bi,int ei)
{
    if(b>ei||bi>e)
        return 0;
    if(bi<=b&&e<=ei)
        return aint[poz];
    return std::max(maxim(poz*2,b,(b+e)/2,bi,ei),
               maxim(poz*2+1,(b+e)/2+1,e,bi,ei));
}
int initializare(int nod,int &N)
{
    int p1=pozmin[nod],p2=pozmax[nod];
    for(auto x:a[nod])
        p2=std::max(p2,initializare(x,N));
    update(1,1,N,p1,p2);
    return p2;
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S)
{
    a.clear();
    a.resize(N+5);
    for(int i=1;i<=4*N;++i)
        aint[i]=0;
    for(int i=1;i<N;++i)
    {
        a[F[i]].push_back(i);
        pozmin[i]=N;
        pozmax[i]=0;
    }
    for(int i=0;i<M;++i)
        for(int j=0;j<N-1;++j)
        {
            pozmin[S[i][j]]=std::min(pozmin[S[i][j]],j+1);
            pozmax[S[i][j]]=std::max(pozmax[S[i][j]],j+1);
        }
    initializare(0,N);
    int poz=1,ans=0;
    while(poz<N)
    {
        int bi=poz,ei=poz;
        while(maxim(1,1,N,bi,ei)!=ei)
            ei=maxim(1,1,N,bi,ei);
        poz=ei+1;
        ++ans;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 240 ms 21636 KB Output is correct
5 Correct 213 ms 21880 KB Output is correct
6 Correct 222 ms 21640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 240 ms 21636 KB Output is correct
19 Correct 213 ms 21880 KB Output is correct
20 Correct 222 ms 21640 KB Output is correct
21 Correct 267 ms 15960 KB Output is correct
22 Correct 282 ms 16056 KB Output is correct
23 Correct 274 ms 16468 KB Output is correct
24 Correct 244 ms 16404 KB Output is correct
25 Correct 274 ms 16052 KB Output is correct
26 Correct 299 ms 16016 KB Output is correct
27 Correct 249 ms 17180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 240 ms 21636 KB Output is correct
8 Correct 213 ms 21880 KB Output is correct
9 Correct 222 ms 21640 KB Output is correct
10 Correct 79 ms 21776 KB Output is correct
11 Correct 88 ms 21960 KB Output is correct
12 Correct 79 ms 21964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 240 ms 21636 KB Output is correct
36 Correct 213 ms 21880 KB Output is correct
37 Correct 222 ms 21640 KB Output is correct
38 Correct 267 ms 15960 KB Output is correct
39 Correct 282 ms 16056 KB Output is correct
40 Correct 274 ms 16468 KB Output is correct
41 Correct 244 ms 16404 KB Output is correct
42 Correct 274 ms 16052 KB Output is correct
43 Correct 299 ms 16016 KB Output is correct
44 Correct 249 ms 17180 KB Output is correct
45 Correct 79 ms 21776 KB Output is correct
46 Correct 88 ms 21960 KB Output is correct
47 Correct 79 ms 21964 KB Output is correct
48 Correct 92 ms 15688 KB Output is correct
49 Correct 113 ms 15560 KB Output is correct
50 Correct 78 ms 16588 KB Output is correct
51 Correct 83 ms 16584 KB Output is correct
52 Correct 91 ms 15560 KB Output is correct
53 Correct 95 ms 15476 KB Output is correct
54 Correct 82 ms 16588 KB Output is correct