답안 #441558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441558 2021-07-05T11:13:43 Z elazarkoren Exam (eJOI20_exam) C++17
0 / 100
1000 ms 500 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() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    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]);
//        vi prefix(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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 332 KB Output is correct
3 Correct 148 ms 344 KB Output is correct
4 Correct 984 ms 392 KB Output is correct
5 Execution timed out 1069 ms 500 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -