답안 #466685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466685 2021-08-20T07:47:29 Z Valaki2 Exam (eJOI20_exam) C++14
12 / 100
58 ms 3516 KB
#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> a;
vector<int> b;

void solve_bf() {

}

void solve_bequal() {
    int x = b[1];
    int last = 0;
    bool ok = false;
    int ans = 0;
    a.push_back(x + 1);
    for(int i = 1; i <= (n + 1); ++i) {
        if(a[i] > x) {
            if(ok) {
                ans += i - last - 1;
                ok = false;
            }
            last = i;
        } else if(a[i] == x) {
            ok = true;
        }
    }
    cout << ans << "\n";
}

void solve_astrictlyincreasing() {
    vector<int> dp(1 + n, 0);
    vector<int> last_equal(1 + n, 0);
    for(int i = 1; i <= n; ++i) {
        vector<int> cnt(1 + i + 1, 0);
        for(int j = i; j >= 1; --j) {
            cnt[j] = cnt[j + 1];
            if(b[j] == a[i]) {
                ++cnt[j];
                if(!last_equal[i]) last_equal[i] = j;
            }
        }
        for(int j = i; j >= 1; --j) {
            if(dp[i] < dp[j - 1] + cnt[last_equal[j - 1] + 1]) {
                dp[i] = dp[j - 1] + cnt[last_equal[j - 1] + 1];
                last_equal[i] = max(last_equal[i], last_equal[j - 1]);
            }
            // dp[i] = max(dp[i], dp[j - 1] + cnt[last_equal[j - 1] + 1]);
        }
        // cout << i << ": " << last_equal[i] << " " << dp[i] << "\n";
    }
    cout << dp[n] << "\n";
}

void solve() {
    cin >> n;
    a.assign(1 + n, 0);
    b.assign(1 + n, 0);
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) cin >> b[i];
    set<int> b_set;
    for(int i = 1; i <= n; ++i) {
        b_set.insert(b[i]);
    }
    /*if(n <= 10) {
        solve_bf();
    } else */if(b_set.size() == 1) {
        solve_bequal();
    } else {
        solve_astrictlyincreasing();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 6 ms 844 KB Output is correct
3 Correct 19 ms 2284 KB Output is correct
4 Correct 16 ms 1868 KB Output is correct
5 Correct 39 ms 3516 KB Output is correct
6 Correct 16 ms 1868 KB Output is correct
7 Correct 17 ms 1996 KB Output is correct
8 Correct 27 ms 3396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct