Submission #289459

# Submission time Handle Problem Language Result Execution time Memory
289459 2020-09-02T16:41:37 Z nandonathaniel Railway Trip (JOI17_railway_trip) C++14
20 / 100
2000 ms 8600 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=100005,INF=1e9;
int a[MAXN],L[MAXN],R[MAXN];
vector<int> adj[MAXN];
bool visited[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k,q,u,v;
	cin >> n >> k >> q;
	for(int i=1;i<=n;i++)cin >> a[i];
	stack<int> kiri;
	kiri.push(1);
	for(int i=2;i<=n;i++){
		while(a[kiri.top()]<a[i])kiri.pop();
		adj[i].push_back(kiri.top());
		adj[kiri.top()].push_back(i);
		kiri.push(i);
	}
	stack<int> kanan;
	kanan.push(n);
	for(int i=n-1;i>=1;i--){
		while(a[kanan.top()]<a[i])kanan.pop();
		adj[i].push_back(kanan.top());
		adj[kanan.top()].push_back(i);
		kanan.push(i);
	}
	while(q--){
		for(int i=1;i<=n;i++)visited[i]=0;
		cin >> u >> v;
		queue<pii> Q;
		Q.push({0,u});
		visited[u]=true;
		while(!Q.empty()){
			pii now=Q.front();
			Q.pop();
			if(now.second==v){
				cout << now.first-1 << '\n';
				break;
			}
			for(auto nxt : adj[now.second]){
				if(!visited[nxt]){
					visited[nxt]=true;
					Q.push({now.first+1,nxt});
				}
			}
		}
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 140 ms 7812 KB Output is correct
3 Correct 163 ms 7808 KB Output is correct
4 Correct 174 ms 7860 KB Output is correct
5 Correct 170 ms 7852 KB Output is correct
6 Correct 162 ms 8000 KB Output is correct
7 Correct 203 ms 8372 KB Output is correct
8 Correct 86 ms 6988 KB Output is correct
9 Correct 98 ms 7672 KB Output is correct
10 Correct 102 ms 7288 KB Output is correct
11 Correct 159 ms 7928 KB Output is correct
12 Correct 141 ms 8016 KB Output is correct
13 Correct 150 ms 7980 KB Output is correct
14 Correct 136 ms 7928 KB Output is correct
15 Correct 153 ms 8004 KB Output is correct
16 Correct 150 ms 8044 KB Output is correct
17 Correct 227 ms 8324 KB Output is correct
18 Correct 196 ms 8428 KB Output is correct
19 Correct 138 ms 7748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2080 ms 8104 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 8600 KB Time limit exceeded
2 Halted 0 ms 0 KB -