# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
735164 | 2023-05-03T16:23:25 Z | arnold518 | Passport (JOI23_passport) | C++17 | 2000 ms | 666036 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; int N, Q; pii A[MAXN+10]; vector<int> adj[MAXN+10]; int D1[MAXN+10], D2[MAXN+10], D3[MAXN+10]; void bfs(int *D) { queue<pii> Q; vector<pii> V; for(int i=1; i<=N; i++) if(D[i]) V.push_back({D[i], i}); sort(V.begin(), V.end()); for(int p=0; p<V.size();) { Q.push({V[p].second, V[p].first}); p++; while(!Q.empty()) { pii t=Q.front(); Q.pop(); if(D[t.first]!=t.second) continue; int now=t.first; for(; p<V.size() && V[p].first<=D[now]+1; p++) Q.push({V[p].second, V[p].first}); for(auto nxt : adj[now]) { if(D[nxt]!=0 && D[nxt]<=D[now]+1) continue; D[nxt]=D[now]+1; Q.push({nxt, D[nxt]}); } } } for(int i=1; i<=N; i++) if(!D[i]) D[i]=N+N; } int main() { scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second); for(int i=1; i<=N; i++) { auto [l, r]=A[i]; for(int j=l; j<=r; j++) adj[j].push_back(i); } for(int i=1; i<=N; i++) if(A[i].first==1) D1[i]=1; bfs(D1); for(int i=1; i<=N; i++) if(A[i].second==N) D2[i]=1; bfs(D2); for(int i=1; i<=N; i++) D3[i]=D1[i]+D2[i]-1; bfs(D3); scanf("%d", &Q); while(Q--) { int t; scanf("%d", &t); if(D3[t]>N) D3[t]=-1; printf("%d\n", D3[t]); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Execution timed out | 2102 ms | 666036 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 4948 KB | Output is correct |
6 | Correct | 3 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5016 KB | Output is correct |
10 | Correct | 3 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5076 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 5204 KB | Output is correct |
14 | Correct | 3 ms | 5204 KB | Output is correct |
15 | Correct | 3 ms | 5076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 4948 KB | Output is correct |
6 | Correct | 3 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5016 KB | Output is correct |
10 | Correct | 3 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5076 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 5204 KB | Output is correct |
14 | Correct | 3 ms | 5204 KB | Output is correct |
15 | Correct | 3 ms | 5076 KB | Output is correct |
16 | Correct | 21 ms | 13340 KB | Output is correct |
17 | Correct | 5 ms | 5204 KB | Output is correct |
18 | Correct | 53 ms | 22076 KB | Output is correct |
19 | Correct | 40 ms | 21256 KB | Output is correct |
20 | Correct | 3 ms | 5204 KB | Output is correct |
21 | Correct | 8 ms | 7432 KB | Output is correct |
22 | Correct | 43 ms | 25200 KB | Output is correct |
23 | Correct | 36 ms | 19284 KB | Output is correct |
24 | Correct | 31 ms | 19940 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 4948 KB | Output is correct |
6 | Correct | 3 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5016 KB | Output is correct |
10 | Correct | 3 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5076 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 5204 KB | Output is correct |
14 | Correct | 3 ms | 5204 KB | Output is correct |
15 | Correct | 3 ms | 5076 KB | Output is correct |
16 | Correct | 21 ms | 13340 KB | Output is correct |
17 | Correct | 5 ms | 5204 KB | Output is correct |
18 | Correct | 53 ms | 22076 KB | Output is correct |
19 | Correct | 40 ms | 21256 KB | Output is correct |
20 | Correct | 3 ms | 5204 KB | Output is correct |
21 | Correct | 8 ms | 7432 KB | Output is correct |
22 | Correct | 43 ms | 25200 KB | Output is correct |
23 | Correct | 36 ms | 19284 KB | Output is correct |
24 | Correct | 31 ms | 19940 KB | Output is correct |
25 | Correct | 3 ms | 4948 KB | Output is correct |
26 | Correct | 2 ms | 4948 KB | Output is correct |
27 | Correct | 25 ms | 13796 KB | Output is correct |
28 | Correct | 8 ms | 5204 KB | Output is correct |
29 | Correct | 6 ms | 5204 KB | Output is correct |
30 | Correct | 13 ms | 7304 KB | Output is correct |
31 | Correct | 23 ms | 15164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Execution timed out | 2102 ms | 666036 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |