답안 #799677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799677 2023-07-31T19:31:25 Z josiftepe Exam (eJOI20_exam) C++14
77 / 100
257 ms 99476 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
int a[maxn], b[maxn];
int L[maxn], R[maxn];
void solve_subtask2() {
    int x = b[0];
    int res = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == x) {
            res++;
            int j = i - 1;
            while(j >= 0 and a[j] <= x) {
                j--;
                res++;
            }
            j = i + 1;
            while(j < n and a[j] <= x) {
                res++;
                j++;
            }
            i = j - 1;
        }
    }
    cout << res << endl;
}
int dp[5005][5005];
int rec(int i, int j) {
    if(i < 0 or j < 0) {
        return 0;
    }
    if(dp[i][j] != -1) {
        return dp[i][j];
    }
    int res = 0;
    if(a[i] == b[j] and L[i] < j and R[i] > j) {
        res = max(res, rec(i, j - 1) + 1);
    }
    res = max(res, rec(i - 1, j));
    res = max(res, rec(i, j - 1));
    return dp[i][j] = res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    set<int> st;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
        st.insert(b[i]);
    }
    
    if((int) st.size() == 1) {
        solve_subtask2();
        return 0;
    }
    else if(n <= 5005){
        for(int i = 0; i < n; i++) {
            int idx1 = -1;
            for(int j = 0; j < i; j++) {
                if(a[i] < a[j]) {
                    idx1 = j;
                }
            }
            int idx2 = n;
            for(int j = i + 1; j < n; j++) {
                if(a[i] < a[j]) {
                    idx2 = j;
                    break;
                }
            }
            L[i] = idx1;
            R[i] = idx2;
        }
        memset(dp, -1, sizeof dp);
        cout << rec(n - 1, n - 1) << endl;
    }
    
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 98336 KB Output is correct
2 Correct 32 ms 98332 KB Output is correct
3 Correct 33 ms 98260 KB Output is correct
4 Correct 34 ms 98252 KB Output is correct
5 Correct 37 ms 98384 KB Output is correct
6 Correct 33 ms 98264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 12 ms 1040 KB Output is correct
4 Correct 9 ms 1108 KB Output is correct
5 Correct 16 ms 1000 KB Output is correct
6 Correct 9 ms 1108 KB Output is correct
7 Correct 10 ms 1000 KB Output is correct
8 Correct 17 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 98252 KB Output is correct
2 Correct 34 ms 98388 KB Output is correct
3 Correct 54 ms 98768 KB Output is correct
4 Correct 159 ms 99284 KB Output is correct
5 Correct 165 ms 99424 KB Output is correct
6 Correct 167 ms 99476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 99312 KB Output is correct
2 Incorrect 12 ms 2516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 98336 KB Output is correct
2 Correct 32 ms 98332 KB Output is correct
3 Correct 33 ms 98260 KB Output is correct
4 Correct 34 ms 98252 KB Output is correct
5 Correct 37 ms 98384 KB Output is correct
6 Correct 33 ms 98264 KB Output is correct
7 Correct 33 ms 98328 KB Output is correct
8 Correct 34 ms 98300 KB Output is correct
9 Correct 34 ms 98336 KB Output is correct
10 Correct 36 ms 98336 KB Output is correct
11 Correct 36 ms 98392 KB Output is correct
12 Correct 35 ms 98320 KB Output is correct
13 Correct 36 ms 98380 KB Output is correct
14 Correct 39 ms 98324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 98336 KB Output is correct
2 Correct 32 ms 98332 KB Output is correct
3 Correct 33 ms 98260 KB Output is correct
4 Correct 34 ms 98252 KB Output is correct
5 Correct 37 ms 98384 KB Output is correct
6 Correct 33 ms 98264 KB Output is correct
7 Correct 32 ms 98252 KB Output is correct
8 Correct 34 ms 98388 KB Output is correct
9 Correct 54 ms 98768 KB Output is correct
10 Correct 159 ms 99284 KB Output is correct
11 Correct 165 ms 99424 KB Output is correct
12 Correct 167 ms 99476 KB Output is correct
13 Correct 33 ms 98328 KB Output is correct
14 Correct 34 ms 98300 KB Output is correct
15 Correct 34 ms 98336 KB Output is correct
16 Correct 36 ms 98336 KB Output is correct
17 Correct 36 ms 98392 KB Output is correct
18 Correct 35 ms 98320 KB Output is correct
19 Correct 36 ms 98380 KB Output is correct
20 Correct 39 ms 98324 KB Output is correct
21 Correct 34 ms 98388 KB Output is correct
22 Correct 40 ms 98564 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 257 ms 99196 KB Output is correct
25 Correct 178 ms 99328 KB Output is correct
26 Correct 171 ms 99276 KB Output is correct
27 Correct 178 ms 99148 KB Output is correct
28 Correct 164 ms 99468 KB Output is correct
29 Correct 175 ms 99392 KB Output is correct
30 Correct 169 ms 99324 KB Output is correct
31 Correct 171 ms 99276 KB Output is correct
32 Correct 168 ms 99352 KB Output is correct