답안 #888872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888872 2023-12-18T10:06:08 Z viwlesxq Passport (JOI23_passport) C++17
22 / 100
2000 ms 25024 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T> 
bool chmin(S &a, const T &b) {
    return (a > b ? (a = b) == b : false);
}
template<class S, class T> 
bool chmax(S &a, const T &b) {
    return (a < b ? (a = b) == b : false);
}
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 998244353;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    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;
    while (q--) {
        int x;
        cin >> x;
        x--;
        if (!x) {
            int res = 0, last = -1;
            bool flag = true;
            priority_queue<int> q;
            q.push(r[x]);
            for (int i = 1; i < n; ++i) {
                if (last < i) {
                    if (q.empty() || q.top() < i) {
                        flag = false;
                        break;
                    }
                    last = q.top();
                    q.pop();
                    res++;
                }
                q.push(r[i]);
            }
            cout << (flag ? res : -1) << '\n';
        } else {
            vector<vector<int>> d(n, vector<int> (n, inf));
            queue<pair<int, int>> q;
            d[l[x]][r[x]] = 1;
            q.push({l[x], r[x]});
            while (!q.empty()) {
                auto [L, R] = q.front(); 
                q.pop();
                for (int i = L; i <= R; ++i) {
                    int new_l = min(L, l[i]), new_r = max(R, r[i]);
                    if (chmin(d[new_l][new_r], d[L][R] + 1)) {
                        q.push({new_l, new_r});
                    }
                }
            }
            cout << (d[0][n - 1] == inf ? -1 : d[0][n - 1]) << '\n';
        }
    }
}
# 결과 실행 시간 메모리 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 27 ms 3140 KB Output is correct
5 Correct 29 ms 3136 KB Output is correct
6 Correct 24 ms 1996 KB Output is correct
7 Correct 20 ms 3032 KB Output is correct
8 Correct 17 ms 2272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 1353 ms 23932 KB Output is correct
17 Correct 1108 ms 24992 KB Output is correct
18 Correct 28 ms 25024 KB Output is correct
19 Correct 43 ms 23640 KB Output is correct
20 Execution timed out 2053 ms 24920 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 1353 ms 23932 KB Output is correct
17 Correct 1108 ms 24992 KB Output is correct
18 Correct 28 ms 25024 KB Output is correct
19 Correct 43 ms 23640 KB Output is correct
20 Execution timed out 2053 ms 24920 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 27 ms 3140 KB Output is correct
5 Correct 29 ms 3136 KB Output is correct
6 Correct 24 ms 1996 KB Output is correct
7 Correct 20 ms 3032 KB Output is correct
8 Correct 17 ms 2272 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 1353 ms 23932 KB Output is correct
25 Correct 1108 ms 24992 KB Output is correct
26 Correct 28 ms 25024 KB Output is correct
27 Correct 43 ms 23640 KB Output is correct
28 Execution timed out 2053 ms 24920 KB Time limit exceeded
29 Halted 0 ms 0 KB -