Submission #469035

# Submission time Handle Problem Language Result Execution time Memory
469035 2021-08-30T12:59:57 Z kderylo Exam (eJOI20_exam) C++17
77 / 100
187 ms 165564 KB
#include <iostream>
#include <vector>
using namespace std;
const int stala=1e5+10;
const int stala2=5010;
int tab[stala];
int tab2[stala];
int przedzialy[stala][2];
int dp[stala2][stala2];
int pref[stala2][stala2];
vector<int>wektor;
vector<int>wektor2;
void wyznacz_przedzial(int ile)
{
    for(int i=1;i<=ile;i++)
    {
        while(!wektor.empty()&&wektor.back()<=tab[i])
        {
            przedzialy[wektor2.back()][1]=i-1;
            wektor.pop_back();
            wektor2.pop_back();
        }
        wektor.push_back(tab[i]);
        wektor2.push_back(i);
    }
    while(!wektor.empty())
    {
        przedzialy[wektor2.back()][1]=ile;
        wektor.pop_back();
        wektor2.pop_back();
    }
    for(int i=ile;i>=1;i--)
    {
        while(!wektor.empty()&&wektor.back()<=tab[i])
        {
            przedzialy[wektor2.back()][0]=i+1;
            wektor.pop_back();
            wektor2.pop_back();
        }
        wektor.push_back(tab[i]);
        wektor2.push_back(i);
    }
    while(!wektor.empty())
    {
        przedzialy[wektor2.back()][0]=1;
        wektor.pop_back();
        wektor2.pop_back();
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ile;
    cin>>ile;
    for(int i=1;i<=ile;i++)
    {
        cin>>tab[i];
    }
    for(int i=1;i<=ile;i++)
    {
        cin>>tab2[i];
    }
    wyznacz_przedzial(ile);
    if(ile<=5000)
    {
        for(int i=1;i<=ile;i++)
        {
            for(int j=1;j<=ile;j++)
            {
                if(przedzialy[j][0]<=i&&i<=przedzialy[j][1])
                {
                    dp[i][j]=max(dp[i-1][j],pref[i-1][j-1]);
                    if(tab[j]==tab2[i])
                    {
                        dp[i][j]++;
                    }
                }
                pref[i][j]=max(pref[i][j-1],dp[i][j]);
            }
        }
        int res=0;
        for(int i=1;i<=ile;i++)
        {
            res=max(res,dp[ile][i]);
        }
        cout<<res;
    }
    else
    {
        int takie_same=tab2[1];
        bool xyz=true;
        for(int i=2;i<=ile;i++)
        {
            if(tab2[i]!=takie_same)
            {
                xyz=false;
                break;
            }
        }
        if(xyz==true)
        {
            int res=0;
            int maks=0;
            for(int i=1;i<=ile;i++)
            {
                if(tab[i]==takie_same)
                {
                    res+=przedzialy[i][1]-przedzialy[i][0]+1;
                    if(maks>=przedzialy[i][0])
                    {
                        res-=(maks-przedzialy[i][0]+1);
                    }
                    maks=max(maks,przedzialy[i][1]);
                }
            }
            cout<<res;
        }
        else
        {
            cout<<"0";
        }
    }


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12876 KB Output is correct
2 Correct 6 ms 588 KB Output is correct
3 Correct 21 ms 3628 KB Output is correct
4 Correct 17 ms 2252 KB Output is correct
5 Correct 33 ms 3836 KB Output is correct
6 Correct 22 ms 2164 KB Output is correct
7 Correct 20 ms 2376 KB Output is correct
8 Correct 30 ms 3776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 5 ms 5836 KB Output is correct
3 Correct 42 ms 39976 KB Output is correct
4 Correct 165 ms 157660 KB Output is correct
5 Correct 169 ms 165456 KB Output is correct
6 Correct 178 ms 165444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 2124 KB Output is correct
11 Correct 2 ms 2124 KB Output is correct
12 Correct 2 ms 2124 KB Output is correct
13 Correct 2 ms 2124 KB Output is correct
14 Correct 2 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 5 ms 5836 KB Output is correct
9 Correct 42 ms 39976 KB Output is correct
10 Correct 165 ms 157660 KB Output is correct
11 Correct 169 ms 165456 KB Output is correct
12 Correct 178 ms 165444 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 2 ms 2124 KB Output is correct
17 Correct 2 ms 2124 KB Output is correct
18 Correct 2 ms 2124 KB Output is correct
19 Correct 2 ms 2124 KB Output is correct
20 Correct 2 ms 2124 KB Output is correct
21 Correct 2 ms 2124 KB Output is correct
22 Correct 14 ms 14668 KB Output is correct
23 Correct 166 ms 118572 KB Output is correct
24 Correct 173 ms 118604 KB Output is correct
25 Correct 164 ms 119332 KB Output is correct
26 Correct 165 ms 126020 KB Output is correct
27 Correct 166 ms 136644 KB Output is correct
28 Correct 178 ms 153564 KB Output is correct
29 Correct 183 ms 165500 KB Output is correct
30 Correct 187 ms 165504 KB Output is correct
31 Correct 185 ms 165564 KB Output is correct
32 Correct 169 ms 142956 KB Output is correct