Submission #888890

# Submission time Handle Problem Language Result Execution time Memory
888890 2023-12-18T10:41:23 Z Alihan_8 Passport (JOI23_passport) C++17
16 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

const int inf = 1e15 + 1;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <int> L(n), R(n);
    for ( int i = 0; i < n; i++ ){
        cin >> L[i] >> R[i];
        --L[i], --R[i];
    }
    int q; cin >> q;
    vector <int> qu(q), p(q);
    for ( auto &x: qu ){
        cin >> x;
        --x;
    }
    iota(all(p), 0);
    sort(all(p), [&](int &x, int &y){
         return R[qu[x]] - L[qu[x]] > R[qu[y]] - L[qu[y]];
    });
    vector <vector<int>> dp(n, vector <int> (n, -1));
    dp[0][n - 1] = 0;
    auto dfs = [&](auto dfs, int l, int r) -> int{
        auto &ret = dp[l][r];
        if ( ret != -1 ){
            return ret;
        } ret = inf;
        for ( int i = l; i <= r; i++ ){
            if ( L[i] < l || R[i] > r ){
                chmin(ret, dfs(dfs, min(l, L[i]), max(r, R[i])) + 1);
            }
        }
        return ret;
    };
    vector <int> ans(q);
    for ( auto &i: p ){
        int s = qu[i];
        if ( !s && q == 1 ){
            int ans = 0, lst = -1;
            bool flag = true;
            priority_queue <int> q;
            q.push(R[s]);
            for ( int i = 1; i < n; i++ ){
                if ( lst < i ){
                    if ( q.empty() || q.top() < i ){
                        flag = false;
                        break;
                    }
                    lst = q.top();
                    q.pop(); ++ans;
                } q.push(R[i]);
            }
            cout << (flag ? ans : -1) << ln;
            return 0;
        }
        ans[i] = dfs(dfs, L[s], R[s]);
    }
    for ( auto &x: ans ){
        cout << (x == inf ? -1 : x + 1) << ln;
    }

    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 431 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 1846 ms 43308 KB Output is correct
17 Correct 857 ms 48992 KB Output is correct
18 Correct 33 ms 49500 KB Output is correct
19 Correct 44 ms 46908 KB Output is correct
20 Execution timed out 2070 ms 49500 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 1846 ms 43308 KB Output is correct
17 Correct 857 ms 48992 KB Output is correct
18 Correct 33 ms 49500 KB Output is correct
19 Correct 44 ms 46908 KB Output is correct
20 Execution timed out 2070 ms 49500 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 431 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -