# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
549007 | LucaDantas | Railway Trip (JOI17_railway_trip) | C++17 | 2059 ms | 3284 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e5+10;
int a[maxn], l[maxn], r[maxn], dist[2][maxn];
void bfs(int s, int k) {
for(int i = 0; i < maxn; i++)
dist[k][i] = 0x3f3f3f3f;
dist[k][s] = 0;
queue<int> q;
q.push(s);
while(q.size()) {
int u = q.front(); int d = dist[k][u];
q.pop();
for(int rep = 0; rep < 2; rep++, swap(l[u], r[u]))
if(dist[k][l[u]] > d+1)
q.push(l[u]), dist[k][l[u]] = d+1;
}
}
int main() {
int n, k, q; scanf("%d %d %d", &n, &k, &q);
for(int i = 0; i < n; i++)
scanf("%d", a+i);
l[0] = 0;
for(int i = 1; i < n; i++) {
l[i] = i-1;
while(a[l[i]] < a[i])
l[i] = l[l[i]];
}
r[n-1] = n-1;
for(int i = n-2; i >= 0; i--) {
r[i] = i+1;
while(a[r[i]] < a[i])
r[i] = r[r[i]];
}
while(q--) {
int x, y; scanf("%d %d", &x, &y);
--x, --y;
bfs(x, 0); bfs(y, 1);
int ans = 0x3f3f3f3f;
for(int i = 0; i < n; i++)
ans = min(ans, dist[0][i] + dist[1][i] - 1);
printf("%d\n", ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |