Precreation contest files
This commit is contained in:
32
misc/bdhsg_1015/search.cpp
Normal file
32
misc/bdhsg_1015/search.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
freopen("search.inp", "r", stdin);
|
||||
|
||||
int n, x;
|
||||
cin >> n >> x;
|
||||
vector<int> a(n);
|
||||
for (int &i : a)
|
||||
cin >> i;
|
||||
|
||||
if (x - 1 > n || x < 0) {
|
||||
cout << -1 << '\n';
|
||||
return 0;
|
||||
} else {
|
||||
x = a[x - 1];
|
||||
}
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
// cout << a[i] << '\n';
|
||||
if (a[i] == x) {
|
||||
cout << i + 1 << ' ';
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
cout << '\n';
|
||||
cout << ((cnt == 0) ? -1 : cnt) << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user