Submission #691266

# Submission time Handle Problem Language Result Execution time Memory
691266 2023-01-31T04:07:37 Z amunduzbaev Railway Trip (JOI17_railway_trip) C++17
0 / 100
2000 ms 9564 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;
//~ #define int ll

const int N = 2e5 + 5;
vector<int> edges[N];
int a[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, k, q; cin >> n >> k >> q;
	vector<int> ss;
	for(int i=0;i<n;i++){
		cin >> a[i];
		while(!ss.empty() && a[ss.back()] < a[i]){
			edges[ss.back()].push_back(i);
			edges[i].push_back(ss.back());
			ss.pop_back();
		}
		if(!ss.empty()){
			edges[ss.back()].push_back(i);
			edges[i].push_back(ss.back());
		}
		ss.push_back(i);
	}
	ss.clear();
	int d[n];
	while(q--){
		int a, b; cin >> a >> b; a--, b--;
		memset(d, 63, sizeof d);
		queue<int> q;
		q.push(a); d[a] = 0;
		while(!q.empty()){
			int u = q.front(); q.pop();
			for(auto x : edges[u]){
				if(d[x] > d[u] + 1){
					d[x] = d[u] + 1;
					q.push(x);
				}
			}
		}
		//~ for(int i=0;i<n;i++) cout<<d[i]<<" ";
		//~ cout<<"\n";
		cout<<--d[b]<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2071 ms 9528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 9564 KB Time limit exceeded
2 Halted 0 ms 0 KB -