답안 #382845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382845 2021-03-28T10:02:47 Z valerikk Exam (eJOI20_exam) C++17
30 / 100
900 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    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<int> right(n, n);
    vector<int> st;
    for (int i = 0; i < n; i++) {
        while (!st.empty() && a[st.back()] < a[i]) {
            right[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    
    vector<int> left(n, -1);
    st = {};
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.back()] < a[i]) {
            left[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    
    vector<pair<pair<int, int>, int>> events;
    for (int i = 0; i < n; i++) {
        for (int l = left[i] + 1; l < right[i]; l++) {
            int cnt = 0;
            for (int r = l; r < right[i]; r++) {
                if (b[r] == a[i]) cnt++;
                events.push_back({{l, r}, cnt});
            }
        }
    }
    
    vector<int> dp(n + 1, 0);
    for (auto e : events) {
        int l = e.first.first, r = e.first.second, cnt = e.second;
        dp[r + 1] = max(dp[r + 1], dp[l] + cnt);
    }
    
    cout << dp[n] << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 98928 KB Output is correct
2 Runtime error 900 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 679 ms 394580 KB Output is correct
3 Runtime error 861 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 848 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 688 KB Output is correct
9 Correct 4 ms 2020 KB Output is correct
10 Correct 11 ms 6620 KB Output is correct
11 Correct 4 ms 2020 KB Output is correct
12 Correct 4 ms 2020 KB Output is correct
13 Correct 4 ms 2020 KB Output is correct
14 Correct 44 ms 25168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 679 ms 394580 KB Output is correct
9 Runtime error 861 ms 524292 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -