# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
201573 | 2020-02-11T06:57:48 Z | arnold518 | Railway Trip (JOI17_railway_trip) | C++14 | 2000 ms | 9700 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 = 1e5; int N, K, Q, A[MAXN+10]; vector<pii> E; vector<int> adj[MAXN+10]; int dist[MAXN+10]; int main() { int i, j; scanf("%d%d%d", &N, &K, &Q); for(i=1; i<=N; i++) scanf("%d", &A[i]); vector<int> S; S.clear(); S.push_back(1); for(i=2; i<=N; i++) { while(!S.empty() && A[S.back()]<A[i]) S.pop_back(); E.push_back({S.back(), i}); S.push_back(i); } S.clear(); S.push_back(N); for(i=N-1; i>=1; i--) { while(!S.empty() && A[S.back()]<A[i]) S.pop_back(); E.push_back({i, S.back()}); S.push_back(i); } sort(E.begin(), E.end()); E.erase(unique(E.begin(), E.end()), E.end()); for(auto it : E) adj[it.first].push_back(it.second), adj[it.second].push_back(it.first); while(Q--) { int x, y; scanf("%d%d", &x, &y); memset(dist, -1, sizeof(dist)); queue<int> Q; Q.push(x); dist[x]=0; while(!Q.empty()) { int now=Q.front(); Q.pop(); for(auto nxt : adj[now]) { if(dist[nxt]!=-1) continue; Q.push(nxt); dist[nxt]=dist[now]+1; } } printf("%d\n", dist[y]-1); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 3064 KB | Output is correct |
2 | Correct | 7 ms | 3064 KB | Output is correct |
3 | Correct | 7 ms | 3064 KB | Output is correct |
4 | Correct | 7 ms | 3064 KB | Output is correct |
5 | Correct | 7 ms | 3064 KB | Output is correct |
6 | Correct | 7 ms | 3064 KB | Output is correct |
7 | Correct | 7 ms | 3064 KB | Output is correct |
8 | Correct | 7 ms | 3064 KB | Output is correct |
9 | Correct | 7 ms | 3064 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3192 KB | Output is correct |
2 | Correct | 220 ms | 8804 KB | Output is correct |
3 | Correct | 239 ms | 8932 KB | Output is correct |
4 | Correct | 239 ms | 9060 KB | Output is correct |
5 | Correct | 254 ms | 9060 KB | Output is correct |
6 | Correct | 247 ms | 9188 KB | Output is correct |
7 | Correct | 249 ms | 9444 KB | Output is correct |
8 | Correct | 127 ms | 8800 KB | Output is correct |
9 | Correct | 119 ms | 8936 KB | Output is correct |
10 | Correct | 122 ms | 8804 KB | Output is correct |
11 | Correct | 190 ms | 9060 KB | Output is correct |
12 | Correct | 189 ms | 9060 KB | Output is correct |
13 | Correct | 193 ms | 8932 KB | Output is correct |
14 | Correct | 185 ms | 9060 KB | Output is correct |
15 | Correct | 192 ms | 9060 KB | Output is correct |
16 | Correct | 188 ms | 9060 KB | Output is correct |
17 | Correct | 251 ms | 9444 KB | Output is correct |
18 | Correct | 268 ms | 9484 KB | Output is correct |
19 | Correct | 167 ms | 9444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2065 ms | 8932 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2069 ms | 9700 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |