답안 #875911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875911 2023-11-20T18:04:00 Z maxFedorchuk Exam (eJOI20_exam) C++14
65 / 100
177 ms 99292 KB
#include<bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)

using namespace std;

const int N=5e3+10, L=28;
int n, a[N], b[N], st[N][L], dp[N][N];

void build()
{
    FOR(i, 1, L)
    {
        for(int j=1; j+(1<<i)-1<=n; j++)
        {
            st[j][i]=max(st[j][i-1], st[j+(1<<(i-1))][i-1]);
        }
    }
}

int get(int l, int r)
{
    int ln=r-l+1;
    int k=0;

    while((1<<(k+1))<=ln)
    {
        k++;
    }

    return max(st[l][k], st[r-(1<<k)+1][k]);
}

int main()
{
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> a[i+1];
        st[i+1][0]=a[i+1];
    }

    FOR(i, 0, n) cin >> b[i+1];

    build();

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i]==b[j])
            {
                int mx=get(min(i, j), max(i, j));

                if(mx==a[i])
                {
                    dp[i][j]+=max(dp[i][j-1], dp[i-1][j-1])+1;
                }
                else
                {
                    dp[i][j]=max({ dp[i-1][j], dp[i][j-1], dp[i-1][j-1] });
                }
            }
            else
            {
                dp[i][j]=max({ dp[i-1][j], dp[i][j-1] , dp[i-1][j-1] });
            }
        }
    }

    cout << dp[n][n]<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12124 KB Output is correct
2 Runtime error 6 ms 5244 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 3 ms 5344 KB Output is correct
3 Correct 25 ms 31884 KB Output is correct
4 Correct 107 ms 97108 KB Output is correct
5 Correct 112 ms 99156 KB Output is correct
6 Correct 115 ms 99252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 99152 KB Output is correct
2 Runtime error 6 ms 5212 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2532 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 1 ms 3420 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2532 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 5344 KB Output is correct
9 Correct 25 ms 31884 KB Output is correct
10 Correct 107 ms 97108 KB Output is correct
11 Correct 112 ms 99156 KB Output is correct
12 Correct 115 ms 99252 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 1 ms 3420 KB Output is correct
18 Correct 1 ms 3420 KB Output is correct
19 Correct 1 ms 3420 KB Output is correct
20 Correct 1 ms 3420 KB Output is correct
21 Correct 1 ms 3420 KB Output is correct
22 Correct 8 ms 12124 KB Output is correct
23 Correct 177 ms 99252 KB Output is correct
24 Correct 172 ms 99292 KB Output is correct
25 Correct 117 ms 99220 KB Output is correct
26 Correct 112 ms 99192 KB Output is correct
27 Correct 111 ms 99176 KB Output is correct
28 Correct 113 ms 99272 KB Output is correct
29 Correct 112 ms 99160 KB Output is correct
30 Correct 113 ms 99204 KB Output is correct
31 Correct 114 ms 99228 KB Output is correct
32 Correct 112 ms 99156 KB Output is correct