Submission #2715256
Source Code Expand
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt() ; int[] a = new int[N]; boolean[] pushFlg = new boolean[N]; for (int i = 0; i < N; i++) { a[i] = sc.nextInt(); } int lightButton = 1; boolean relightFlg = false ; int count = 0; while(!relightFlg){ if (lightButton == 2) { break; } pushFlg[lightButton - 1] = true; lightButton = a[lightButton - 1]; count ++; if(pushFlg[lightButton - 1]){ relightFlg = true; } } System.out.println(relightFlg ? -1 : count); } }
Submission Info
Submission Time | |
---|---|
Task | B - Trained? |
User | shosinsha |
Language | Java8 (OpenJDK 1.8.0) |
Score | 200 |
Code Size | 822 Byte |
Status | AC |
Exec Time | 433 ms |
Memory | 51164 KB |
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 | 418 ms | 46524 KB |
02.txt | AC | 408 ms | 48680 KB |
03.txt | AC | 410 ms | 46860 KB |
04.txt | AC | 433 ms | 45768 KB |
05.txt | AC | 414 ms | 47812 KB |
06.txt | AC | 410 ms | 51164 KB |
07.txt | AC | 409 ms | 48708 KB |
08.txt | AC | 421 ms | 46384 KB |
09.txt | AC | 407 ms | 47780 KB |
10.txt | AC | 417 ms | 45304 KB |
11.txt | AC | 430 ms | 49152 KB |
12.txt | AC | 407 ms | 49868 KB |
13.txt | AC | 409 ms | 45628 KB |
14.txt | AC | 412 ms | 48056 KB |
15.txt | AC | 393 ms | 44156 KB |
16.txt | AC | 402 ms | 47900 KB |
17.txt | AC | 410 ms | 46724 KB |
18.txt | AC | 410 ms | 49428 KB |
19.txt | AC | 93 ms | 19284 KB |
20.txt | AC | 92 ms | 19156 KB |
21.txt | AC | 91 ms | 18644 KB |
22.txt | AC | 92 ms | 19540 KB |
s1.txt | AC | 91 ms | 19412 KB |
s2.txt | AC | 92 ms | 18640 KB |
s3.txt | AC | 92 ms | 18644 KB |