Submission #959595

# Submission time Handle Problem Language Result Execution time Memory
959595 2024-04-08T13:31:48 Z TAhmed33 Passport (JOI23_passport) C++
48 / 100
2000 ms 826892 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 25;
const int inf = MAXN << 4;
int n, q;
pair <int, int> a[MAXN];
vector <pair <int, int>> radj[MAXN];
int dist1[MAXN], dist2[MAXN], dist3[MAXN];
int main () {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
        for (int j = a[i].first; j <= a[i].second; j++) {
            radj[j].push_back({i + n, 0});
        }
    }
    for (int i = 1; i <= n; i++) {
        radj[i + n].push_back({i, 1});
    }
    for (int i = 1; i <= 2 * n; i++) {
        dist1[i] = dist2[i] = inf;
    }
    priority_queue <pair <int, int>, vector <pair <int, int>>, greater <>> cur;
    cur.push({0, 1}); dist1[1] = 0;
    while (!cur.empty()) {
        auto k = cur.top();
        cur.pop();
        if (k.first > dist1[k.second]) continue;
        for (auto j : radj[k.second]) {
            if (k.first + j.second < dist1[j.first]) {
                dist1[j.first] = k.first + j.second;
                cur.push({dist1[j.first], j.first});
            }
        }
    }
    cur.push({0, n}); dist2[n] = 0;
    while (!cur.empty()) {
        auto k = cur.top();
        cur.pop();
        if (k.first > dist2[k.second]) continue;
        for (auto j : radj[k.second]) {
            if (k.first + j.second < dist2[j.first]) {
                dist2[j.first] = k.first + j.second;
                cur.push({dist2[j.first], j.first});
            }
        }
    }
    for (int i = 1; i <= 2 * n; i++) {
        dist3[i] = dist1[i] + dist2[i];
        cur.push({dist3[i], i});
    }
    while (!cur.empty()) {
        auto k = cur.top();
        cur.pop();
        if (k.first > dist3[k.second]) continue;
        for (auto j : radj[k.second]) {
            if (k.first + j.second < dist3[j.first]) {
                dist3[j.first] = k.first + j.second;
                cur.push({dist3[j.first], j.first});
            }
        }
    }
    for (int i = 1; i <= 2 * n; i++) if (dist3[i] > n) dist3[i] = -1;
    cin >> q;
    while (q--) {
        int x; cin >> x;
        cout << dist3[x] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 31064 KB Output is correct
2 Correct 7 ms 31068 KB Output is correct
3 Correct 7 ms 31156 KB Output is correct
4 Execution timed out 2118 ms 826892 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31068 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Correct 6 ms 31252 KB Output is correct
4 Correct 6 ms 31064 KB Output is correct
5 Correct 6 ms 31068 KB Output is correct
6 Correct 8 ms 31068 KB Output is correct
7 Correct 8 ms 31068 KB Output is correct
8 Correct 6 ms 31068 KB Output is correct
9 Correct 6 ms 31072 KB Output is correct
10 Correct 6 ms 31072 KB Output is correct
11 Correct 7 ms 31856 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 9 ms 31836 KB Output is correct
14 Correct 7 ms 31832 KB Output is correct
15 Correct 6 ms 31324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31068 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Correct 6 ms 31252 KB Output is correct
4 Correct 6 ms 31064 KB Output is correct
5 Correct 6 ms 31068 KB Output is correct
6 Correct 8 ms 31068 KB Output is correct
7 Correct 8 ms 31068 KB Output is correct
8 Correct 6 ms 31068 KB Output is correct
9 Correct 6 ms 31072 KB Output is correct
10 Correct 6 ms 31072 KB Output is correct
11 Correct 7 ms 31856 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 9 ms 31836 KB Output is correct
14 Correct 7 ms 31832 KB Output is correct
15 Correct 6 ms 31324 KB Output is correct
16 Correct 32 ms 47704 KB Output is correct
17 Correct 9 ms 31832 KB Output is correct
18 Correct 61 ms 63572 KB Output is correct
19 Correct 59 ms 62032 KB Output is correct
20 Correct 8 ms 31580 KB Output is correct
21 Correct 15 ms 35988 KB Output is correct
22 Correct 68 ms 68856 KB Output is correct
23 Correct 59 ms 58176 KB Output is correct
24 Correct 51 ms 58808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31068 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Correct 6 ms 31252 KB Output is correct
4 Correct 6 ms 31064 KB Output is correct
5 Correct 6 ms 31068 KB Output is correct
6 Correct 8 ms 31068 KB Output is correct
7 Correct 8 ms 31068 KB Output is correct
8 Correct 6 ms 31068 KB Output is correct
9 Correct 6 ms 31072 KB Output is correct
10 Correct 6 ms 31072 KB Output is correct
11 Correct 7 ms 31856 KB Output is correct
12 Correct 8 ms 31068 KB Output is correct
13 Correct 9 ms 31836 KB Output is correct
14 Correct 7 ms 31832 KB Output is correct
15 Correct 6 ms 31324 KB Output is correct
16 Correct 32 ms 47704 KB Output is correct
17 Correct 9 ms 31832 KB Output is correct
18 Correct 61 ms 63572 KB Output is correct
19 Correct 59 ms 62032 KB Output is correct
20 Correct 8 ms 31580 KB Output is correct
21 Correct 15 ms 35988 KB Output is correct
22 Correct 68 ms 68856 KB Output is correct
23 Correct 59 ms 58176 KB Output is correct
24 Correct 51 ms 58808 KB Output is correct
25 Correct 7 ms 31064 KB Output is correct
26 Correct 6 ms 31152 KB Output is correct
27 Correct 35 ms 48724 KB Output is correct
28 Correct 9 ms 31832 KB Output is correct
29 Correct 8 ms 31580 KB Output is correct
30 Correct 16 ms 35672 KB Output is correct
31 Correct 42 ms 51544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 31064 KB Output is correct
2 Correct 7 ms 31068 KB Output is correct
3 Correct 7 ms 31156 KB Output is correct
4 Execution timed out 2118 ms 826892 KB Time limit exceeded
5 Halted 0 ms 0 KB -