Submission #45291473
Source Code Expand
#include <iostream> #include <vector> using namespace std; int main(void) { int n = 0; cin >> n; vector<bool> seen(n, false); vector<int> a(n); for (auto &x : a) { cin >> x; x--; } int i = 0, cnt = 0; while (true) { if (i == 1) { cout << cnt << endl; return 0; } int next = a[i]; if (seen[next]) { cout << "-1" << endl; return 0; } cnt++; seen[i] = true; i = next; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Trained? |
User | coolwind0202 |
Language | C++ 20 (gcc 12.2) |
Score | 200 |
Code Size | 523 Byte |
Status | AC |
Exec Time | 17 ms |
Memory | 3740 KiB |
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 | 16 ms | 3700 KiB |
02.txt | AC | 16 ms | 3740 KiB |
03.txt | AC | 17 ms | 3592 KiB |
04.txt | AC | 16 ms | 3736 KiB |
05.txt | AC | 16 ms | 3604 KiB |
06.txt | AC | 16 ms | 3604 KiB |
07.txt | AC | 16 ms | 3652 KiB |
08.txt | AC | 17 ms | 3732 KiB |
09.txt | AC | 16 ms | 3608 KiB |
10.txt | AC | 17 ms | 3596 KiB |
11.txt | AC | 16 ms | 3672 KiB |
12.txt | AC | 16 ms | 3636 KiB |
13.txt | AC | 16 ms | 3736 KiB |
14.txt | AC | 16 ms | 3604 KiB |
15.txt | AC | 16 ms | 3656 KiB |
16.txt | AC | 16 ms | 3596 KiB |
17.txt | AC | 16 ms | 3600 KiB |
18.txt | AC | 16 ms | 3668 KiB |
19.txt | AC | 1 ms | 3396 KiB |
20.txt | AC | 1 ms | 3472 KiB |
21.txt | AC | 1 ms | 3672 KiB |
22.txt | AC | 1 ms | 3672 KiB |
s1.txt | AC | 1 ms | 3480 KiB |
s2.txt | AC | 1 ms | 3480 KiB |
s3.txt | AC | 1 ms | 3672 KiB |