Submission #959582

#TimeUsernameProblemLanguageResultExecution timeMemory
959582TAhmed33Passport (JOI23_passport)C++98
16 / 100
2066 ms201188 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 25; const int inf = MAXN << 4; int n, q; pair <int, int> a[MAXN]; vector <pair <int, int>> adj[MAXN]; int dist[MAXN][MAXN]; int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= 2 * n; i++) { for (int j = 1; j <= 2 * n; j++) { dist[i][j] = inf; } dist[i][i] = 0; } 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++) { adj[i + n].push_back({j, 0}); dist[i + n][j] = 0; } } for (int i = 1; i <= n; i++) { adj[i].push_back({i + n, 1}); dist[i][i + n] = 1; } for (int k = 1; k <= 2 * n; k++) { for (int i = 1; i <= 2 * n; i++) { for (int j = 1; j <= 2 * n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } cin >> q; while (q--) { int x; cin >> x; int mn = inf; for (int i = 1; i <= 2 * n; i++) { mn = min(mn, dist[x][i] + dist[i][1] + dist[i][n]); } cout << (mn == inf ? -1 : mn) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...