Submission #469034

# Submission time Handle Problem Language Result Execution time Memory
469034 2021-08-30T12:59:28 Z kderylo Exam (eJOI20_exam) C++17
0 / 100
1000 ms 390048 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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Runtime error 622 ms 245488 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 201 ms 157744 KB Output is correct
2 Execution timed out 1090 ms 390048 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -