QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288650#7866. Teleportationucup-team2230#WA 0ms3776kbC++141.4kb2023-12-23 10:09:162023-12-23 10:09:16

Judging History

你现在查看的是最新测评结果

  • [2023-12-23 10:09:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3776kb
  • [2023-12-23 10:09:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll=long long;

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using P=pair<int,int>;
using vi=vc<int>;


void solve(){
	int n,x;
	cin>>n>>x;
	vc<int> A(n);
	for(int i=0;i<n;i++) cin>>A[i];
	int ret=0;
	vc<int> dist(n);
	for(int i=0;i<n;i++) dist[i]=n+1;
	queue <int> que;
	if(A[0]!=0){
		dist[A[0]]=1;
		que.push(A[0]);
	} else{
		dist[1]=2;
		que.push(1);
	}
	while(!que.empty()){
		int v=que.front();que.pop();
		int t=(v+1)%n;
		if(dist[t]>dist[v]+1){
			dist[t]=dist[v]+1;
			que.push(t);
		}
		if(dist[A[v]]>dist[v]+1){
			dist[A[v]]=dist[v]+1;
			que.push(A[v]);
		}
	}
	cout<<dist[x]<<endl;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int T=1;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3484kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3776kb

input:

300 25
182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...

output:

6

result:

wrong answer 1st numbers differ - expected: '10', found: '6'