# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
335279 | 2020-12-11T19:30:41 Z | Plurm | Railway Trip (JOI17_railway_trip) | C++11 | 2000 ms | 12524 KB |
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; // cartesian-tree-like graph int d[100005]; vector<int> bckt[100005]; int l[100005]; int n,k,q; void compute(int a){ d[a] = 0; for(int i = 1; i <= k; i++){ for(int x : bckt[i]){ for(int y : g[x]) d[x] = min(d[x], d[y]+1); } reverse(bckt[i].begin(), bckt[i].end()); for(int x : bckt[i]){ for(int y : g[x]) d[x] = min(d[x], d[y]+1); } reverse(bckt[i].begin(), bckt[i].end()); } } int main(){ scanf("%d%d%d",&n,&k,&q); stack<int> stk; for(int i = 1; i <= n; i++){ scanf("%d", l+i); bckt[l[i]].push_back(i); while(!stk.empty() && l[stk.top()] <= l[i]){ g[i].push_back(stk.top()); stk.pop(); } if(!stk.empty() && l[stk.top()] == l[i]) g[i].push_back(stk.top()); stk.push(i); } while(!stk.empty()) stk.pop(); for(int i = n; i > 0; i--){ while(!stk.empty() && l[stk.top()] <= l[i]){ g[i].push_back(stk.top()); stk.pop(); } if(!stk.empty() && l[stk.top()] == l[i]) g[i].push_back(stk.top()); stk.push(i); } while(q--){ int a,b; scanf("%d%d",&a,&b); for(int i = 1; i <= n; i++) d[i] = 1e9; compute(a); vector<int> v(n+1); for(int i = 1; i <= n; i++) v[i] = d[i]; for(int i = 1; i <= n; i++) d[i] = 1e9; compute(b); int ans = 1e9; for(int i = 1; i <= n; i++){ ans = min(ans, v[i] + d[i]); } printf("%d\n", ans-1); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4972 KB | Output is correct |
2 | Correct | 5 ms | 4972 KB | Output is correct |
3 | Correct | 4 ms | 4972 KB | Output is correct |
4 | Correct | 4 ms | 4972 KB | Output is correct |
5 | Correct | 4 ms | 4972 KB | Output is correct |
6 | Correct | 4 ms | 4972 KB | Output is correct |
7 | Correct | 9 ms | 4972 KB | Output is correct |
8 | Correct | 7 ms | 4972 KB | Output is correct |
9 | Correct | 4 ms | 4972 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5100 KB | Output is correct |
2 | Correct | 381 ms | 9196 KB | Output is correct |
3 | Correct | 452 ms | 9196 KB | Output is correct |
4 | Correct | 474 ms | 9068 KB | Output is correct |
5 | Correct | 533 ms | 9132 KB | Output is correct |
6 | Correct | 559 ms | 9068 KB | Output is correct |
7 | Correct | 1051 ms | 10604 KB | Output is correct |
8 | Correct | 178 ms | 9700 KB | Output is correct |
9 | Correct | 192 ms | 10348 KB | Output is correct |
10 | Correct | 171 ms | 10216 KB | Output is correct |
11 | Correct | 472 ms | 10092 KB | Output is correct |
12 | Correct | 428 ms | 9708 KB | Output is correct |
13 | Correct | 477 ms | 9700 KB | Output is correct |
14 | Correct | 466 ms | 9964 KB | Output is correct |
15 | Correct | 482 ms | 9708 KB | Output is correct |
16 | Correct | 486 ms | 9700 KB | Output is correct |
17 | Correct | 486 ms | 9188 KB | Output is correct |
18 | Correct | 484 ms | 9068 KB | Output is correct |
19 | Correct | 357 ms | 12524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2086 ms | 9068 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2068 ms | 10596 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |