# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
620423 | 2022-08-03T05:47:04 Z | 박상훈(#8517) | Railway Trip (JOI17_railway_trip) | C++17 | 2000 ms | 8660 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; int n, k, q, a[100100]; vector<int> adj[100100]; void init(){ vector<int> st; for (int i=1;i<=n;i++){ while(!st.empty() && a[st.back()] <= a[i]){ adj[st.back()].push_back(i); adj[i].push_back(st.back()); st.pop_back(); } st.push_back(i); } assert(st.size()==1); st.pop_back(); for (int i=n;i;i--){ while(!st.empty() && a[st.back()] <= a[i]){ if (a[st.back()]!=a[i]){ adj[st.back()].push_back(i); adj[i].push_back(st.back()); } st.pop_back(); } st.push_back(i); } } int dist[100100]; bool visited[100100]; void bfs(int s){ fill(dist+1, dist+n+1, 1e9); fill(visited+1, visited+n+1, 0); dist[s] = 0; visited[s] = 1; queue<int> q; q.push(s); while(!q.empty()){ int v = q.front(); q.pop(); for (auto &nxt:adj[v]) if (!visited[nxt]){ dist[nxt] = dist[v] + 1; visited[nxt] = 1; q.push(nxt); } } } int main(){ scanf("%d %d %d", &n, &k, &q); for (int i=1;i<=n;i++){ scanf("%d", a+i); } init(); while(q--){ int x, y; scanf("%d %d", &x, &y); bfs(x); printf("%d\n", dist[y] - 1); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Correct | 2 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 2 ms | 2644 KB | Output is correct |
9 | Correct | 2 ms | 2644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2672 KB | Output is correct |
2 | Correct | 181 ms | 7636 KB | Output is correct |
3 | Correct | 238 ms | 7820 KB | Output is correct |
4 | Correct | 217 ms | 7964 KB | Output is correct |
5 | Correct | 215 ms | 8024 KB | Output is correct |
6 | Correct | 240 ms | 8140 KB | Output is correct |
7 | Correct | 196 ms | 8472 KB | Output is correct |
8 | Correct | 81 ms | 6864 KB | Output is correct |
9 | Correct | 84 ms | 7252 KB | Output is correct |
10 | Correct | 84 ms | 7096 KB | Output is correct |
11 | Correct | 159 ms | 7660 KB | Output is correct |
12 | Correct | 139 ms | 7560 KB | Output is correct |
13 | Correct | 145 ms | 7616 KB | Output is correct |
14 | Correct | 159 ms | 7656 KB | Output is correct |
15 | Correct | 150 ms | 7672 KB | Output is correct |
16 | Correct | 139 ms | 7588 KB | Output is correct |
17 | Correct | 213 ms | 8496 KB | Output is correct |
18 | Correct | 234 ms | 8396 KB | Output is correct |
19 | Correct | 144 ms | 8108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2077 ms | 7880 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2071 ms | 8660 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |