# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29087 | 2017-07-18T08:23:22 Z | 김현수(#1170) | Railway Trip (JOI17_railway_trip) | C++14 | 2000 ms | 9768 KB |
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int N = 100005, inf = 1e9; int n, p, k, a[N], d[N]; vector<pii> st; vector<int> adj[N]; queue<int> q; int main() { scanf("%d%d%d",&n,&p,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]); st.push_back({0, inf}); for(int i=1;i<=n;i++) { while(st.back().Y < a[i]) { adj[i].push_back(st.back().X); st.pop_back(); } adj[i].push_back(st.back().X); if(st.back().Y == a[i]) st.pop_back(); st.push_back(pii(i, a[i])); } st.clear(); st.push_back({0, inf}); for(int i=n;i>=1;i--) { while(st.back().Y < a[i]) { adj[i].push_back(st.back().X); st.pop_back(); } adj[i].push_back(st.back().X); if(st.back().Y == a[i]) st.pop_back(); st.push_back(pii(i, a[i])); } while(k--) { int A, B; scanf("%d%d",&A,&B); for(int i=1;i<=n;i++) d[i] = inf; d[A] = 0; q.push(A); while(!q.empty()) { int C = q.front(); q.pop(); for(auto &T : adj[C]) { if(d[T] > d[C] + 1) { d[T] = d[C] + 1; q.push(T); } } } printf("%d\n",d[B]-1); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5148 KB | Output is correct |
2 | Correct | 0 ms | 5148 KB | Output is correct |
3 | Correct | 0 ms | 5148 KB | Output is correct |
4 | Correct | 0 ms | 5148 KB | Output is correct |
5 | Correct | 0 ms | 5148 KB | Output is correct |
6 | Correct | 0 ms | 5148 KB | Output is correct |
7 | Correct | 0 ms | 5148 KB | Output is correct |
8 | Correct | 0 ms | 5148 KB | Output is correct |
9 | Correct | 0 ms | 5148 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5148 KB | Output is correct |
2 | Correct | 226 ms | 9240 KB | Output is correct |
3 | Correct | 226 ms | 9372 KB | Output is correct |
4 | Correct | 253 ms | 9504 KB | Output is correct |
5 | Correct | 256 ms | 9636 KB | Output is correct |
6 | Correct | 263 ms | 9636 KB | Output is correct |
7 | Correct | 286 ms | 9768 KB | Output is correct |
8 | Correct | 63 ms | 8316 KB | Output is correct |
9 | Correct | 59 ms | 8604 KB | Output is correct |
10 | Correct | 73 ms | 8476 KB | Output is correct |
11 | Correct | 203 ms | 8724 KB | Output is correct |
12 | Correct | 206 ms | 8860 KB | Output is correct |
13 | Correct | 203 ms | 8856 KB | Output is correct |
14 | Correct | 199 ms | 8724 KB | Output is correct |
15 | Correct | 196 ms | 8848 KB | Output is correct |
16 | Correct | 243 ms | 8856 KB | Output is correct |
17 | Correct | 279 ms | 9768 KB | Output is correct |
18 | Correct | 283 ms | 9768 KB | Output is correct |
19 | Correct | 129 ms | 9108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2000 ms | 9372 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2000 ms | 9768 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |