Submission #833350

# Submission time Handle Problem Language Result Execution time Memory
833350 2023-08-22T04:49:44 Z vjudge1 Exam (eJOI20_exam) C++17
12 / 100
55 ms 1876 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
typedef long long ll;
const ll MAXN = 1e5 + 5;
const ll INF = 1e9;
#define endl '\n'
#define pll pair <ll, ll>
#define fi first
#define se second

ll n;
ll a [MAXN], b [MAXN];
ll par [MAXN];
ll dp [MAXN];

ll bpk(ll x){
    if(par[x] == x) return x;
    return par[x] = bpk(par[x]);
}

int main(){
    cin >> n;
    ll cnt2 = 0;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i-1] < a[i]) cnt2++;
    }
    ll cnt = 0;
    for(ll i = 1; i <= n; i++){
        cin >> b[i];
        if(b[1] == b[i]) cnt++;
    }
    if(cnt == n){
        ll sblm = 0;
        bool ada = false;
        ll ans = 0;
        a[n+1] = 2*INF;
        for(ll i = 1; i <= n+1; i++){
            if(a[i] == b[1]) ada = true;
            if(a[i] > b[1]){
                if(ada){
                    // cout << i << " " << sblm << endl;
                    ada = false;
                    ans += i-sblm-1;
                }
                sblm = i;
            }
        }
        cout << ans << endl;
        exit(0);
    }
    if(cnt2 == n){
        for(ll i = 1; i <= n; i++){
            par[i] = -1;
            for(ll j = i; j <= n; j++){
                if(a[j] > b[i]) break;
                if(a[j] == b[i]){
                    par[i] = j;
                    break;
                }
            }
        }
        for(ll i = n; i >= 1; i--){
            if(par[i] == -1){
                dp[i] = dp[i+1];
                continue;
            }
            ll tmp = 1;
            for(ll j = i+1; j <= par[i]; j++){
                if(par[j] == -1) continue;
                dp[i] = max(dp[i], tmp+dp[j]);
                if(par[j] >= par[i]) tmp++;
            }
            // cout << tmp << " " <<par[i] << " " << dp[par[i]] << endl;
        }
        // for(ll i = 1; i <= n; i++){
        //     cout << dp[i] << " ";
        // }
        // cout << endl;
        cout << dp[1] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 12 ms 596 KB Output is correct
3 Correct 37 ms 1612 KB Output is correct
4 Correct 21 ms 1876 KB Output is correct
5 Correct 55 ms 1836 KB Output is correct
6 Correct 23 ms 1876 KB Output is correct
7 Correct 24 ms 1740 KB Output is correct
8 Correct 54 ms 1844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -