Submission #235509

# Submission time Handle Problem Language Result Execution time Memory
235509 2020-05-28T11:48:08 Z MvC Railway Trip (JOI17_railway_trip) C++11
5 / 100
5 ms 512 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e2+50;
const ll mod=1e9+7;
using namespace std;
int n,qr,k,l[nmax],v[nmax],d[nmax],i,j,x,y,z;
vector<int>g[nmax];
queue<int>q;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k>>qr;
	for(i=1;i<=n;i++)cin>>l[i];
	for(i=1;i<=n;i++)
	{
		for(j=i-1;j>=1;j--)
		{
			if(l[j]>=l[i])
			{
				g[i].pb(j);
				g[j].pb(i);
				break;
			}
		}
		for(j=i+1;j<=n;j++)
		{
			if(l[j]>=l[i])
			{
				g[i].pb(j);
				g[j].pb(i);
				break;
			}
		}
	}
	while(qr--)
	{
		cin>>x>>y;
		for(i=1;i<=n;i++)v[i]=d[i]=0;
		q.push(x);
		v[x]=1;
		while(!q.empty())
		{
			x=q.front();
			q.pop();
			for(i=0;i<(int)g[x].size();i++)
			{
				z=g[x][i];
				if(v[z])continue;
				v[z]=1;
				q.push(z);
				d[z]=d[x]+1;
			}
		}
		cout<<d[y]-1<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -