Submission #441557

# Submission time Handle Problem Language Result Execution time Memory
441557 2021-07-05T11:12:47 Z elazarkoren Exam (eJOI20_exam) C++17
0 / 100
1000 ms 560 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#define x first
#define y second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long ll;

const int MAX_N = 1e5;
const int mod = 1e9 + 7;
const int MAX = 1e9;

int a[MAX_N], b[MAX_N];

struct Seg{
    int n;
    vi seg;
    Seg(int m) {
        for (n = 1; n < m; n <<= 1);
        seg.resize(2 * n);
    }
    void update(int i, int x) {
        seg[i + n] = x;
        i += n;
        for (i >>= 1; i; i >>= 1) seg[i] = max(seg[2 * i], seg[2 * i + 1]);
    }
    int query(int l, int r) {
        int ans = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) chkmax(ans, seg[l++]);
            if (r & 1) chkmax(ans, seg[--r]);
        }
        return ans;
    }
};

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    vi dp(n);
    dp[0] = a[0] == b[0];
    for (int i = 1; i < n; i++) {
        int suffix_sum = a[i] == b[i];
        dp[i] = dp[i - 1] + (a[i] == b[i]);
        Seg seg(i);
        for (int j = i - 1; j >= 0; j--) {
            seg.update(j, dp[j] + suffix_sum);
            suffix_sum += b[j] == a[i];
        }
        suffix_sum = 0;
        for (int j = i; j >= 0; j--) {
            chkmax(dp[j], seg.query(0, j) - suffix_sum);
            suffix_sum += b[j] == a[i];
        }
        int prefix_sum = 0;
        for (int j = 0; j <= i; j++) {
            prefix_sum += b[j] == a[i];
            chkmax(dp[j], prefix_sum);
        }
    }
    cout << dp[n - 1];
}
//5
//1 2 3 4 6
//4 4 2 6 6
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 204 KB Output is correct
3 Correct 144 ms 360 KB Output is correct
4 Correct 933 ms 560 KB Output is correct
5 Execution timed out 1039 ms 416 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1012 ms 400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -