Submission #463377

# Submission time Handle Problem Language Result Execution time Memory
463377 2021-08-11T04:30:12 Z tengiz05 Exam (eJOI20_exam) C++17
0 / 100
10 ms 8268 KB
#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 5000;

int par[N][N];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }
    
    if (n <= 5000) {
        auto c = a;
        c.insert(c.end(), b.begin(), b.end());
        std::sort(c.begin(), c.end());
        c.erase(std::unique(c.begin(), c.end()), c.end());
        
        for (int i = 0; i < n; i++) {
            a[i] = std::lower_bound(c.begin(), c.end(), a[i]) - c.begin();
            b[i] = std::lower_bound(c.begin(), c.end(), b[i]) - c.begin();
            for (int j = 0; j < n; j++) {
                par[i + 1][j] = par[i][j] + (b[i] == j);
            }
        }
        
        std::vector<int> pref(n + 1), suf(n + 1);
        for (int i = 0; i < n; i++) {
            pref[i + 1] = pref[i] + (a[i] == b[i]);
        }
        for (int i = n - 1; i >= 0; i--) {
            suf[i] = suf[i + 1] + (a[i] == b[i]);
        }
        
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i, mx = 0; j <= n; j++) {
                mx = std::max(mx, a[j - 1]);
                ans = std::max(ans, pref[i - 1] + suf[j] + par[j][mx] - par[i - 1][mx]);
            }
        }
        std::cout << ans << "\n";
    } else {
        
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8268 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -