제출 #466610

#제출 시각아이디문제언어결과실행 시간메모리
466610Error42Exam (eJOI20_exam)C++14
13 / 100
68 ms98484 KiB
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<int> b(n);
    for (int i = 0; i < n; i++)
        cin >> b[i];
    vector<vector<int>> dp(n, vector<int>(n, 0));
    for (int j = 0; j < n; j++) {
        dp[0][j] = b[0] == a[j];
    }
    for (int i = 1; i < n; i++) {
        int max_before = max(dp[i - 1][i - 1], dp[i - 1][i]);
        dp[i][i] = max_before + (b[i] == a[i]);
        for (int j = i + 1; j < n; j++) {
            max_before = max(max_before, dp[i - 1][j]);
            dp[i][j] = max_before + (b[i] == a[j]);
        }
    }
#ifdef _DEBUG
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
#endif // _DEBUG

    cout << dp.back().back() << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...