Submission #2215584
Source Code Expand
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//int→string
//string→int
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
//sqrt
//-------------------------------------------
template<class T>
inline T sqr(T x) { return x * x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
//repetition
//------------------------------------------
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define REPR(i, n) for(int i = n;i >= 0;i--)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
LL func(LL t, LL x){
LL count = t/x;
return count;
}
int main() {
int N; cin >> N;
VI a(N+1);
for(int i=1;i<=N;i++){
scanf("%d", &a[i]);
}
int count = 0;
int button = 1;
while(count <=100020){
if(button == 2){
break;
}
button = a[button];
count++;
}
if(count>=100010){
cout<<-1;
}else {
cout << count;
}
return 0;
}
Submission Info
Submission Time
2018-03-17 16:41:32+0900
Task
B - Trained?
User
ganyariya
Language
C++14 (GCC 5.4.1)
Score
200
Code Size
2626 Byte
Status
AC
Exec Time
11 ms
Memory
640 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:97:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
200 / 200
Status
Set Name
Test Cases
Sample
s1.txt, s2.txt, s3.txt
All
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt, s3.txt
Case Name
Status
Exec Time
Memory
01.txt
AC
11 ms
640 KB
02.txt
AC
11 ms
640 KB
03.txt
AC
11 ms
640 KB
04.txt
AC
11 ms
640 KB
05.txt
AC
11 ms
640 KB
06.txt
AC
11 ms
640 KB
07.txt
AC
11 ms
640 KB
08.txt
AC
11 ms
640 KB
09.txt
AC
11 ms
640 KB
10.txt
AC
11 ms
640 KB
11.txt
AC
11 ms
640 KB
12.txt
AC
10 ms
640 KB
13.txt
AC
11 ms
640 KB
14.txt
AC
11 ms
640 KB
15.txt
AC
10 ms
640 KB
16.txt
AC
10 ms
640 KB
17.txt
AC
10 ms
640 KB
18.txt
AC
10 ms
640 KB
19.txt
AC
1 ms
256 KB
20.txt
AC
1 ms
256 KB
21.txt
AC
1 ms
256 KB
22.txt
AC
1 ms
256 KB
s1.txt
AC
1 ms
256 KB
s2.txt
AC
1 ms
256 KB
s3.txt
AC
1 ms
256 KB