Submission #23637453


Source Code Expand

Copy
import java.util.*;
public class Main {
public static void main(String[] args) {
//
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(sc.next());
}
//
int result = 0;
for (int i = 1; i <= n; i++) {
if (i < a[i] && a[a[i]] == i) {
result++;
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		// 各うさぎについて
		int result = 0;
		for (int i = 1; i <= n; i++) {
			if (i < a[i] && a[a[i]] == i) {
				result++;
			}
		}
		System.out.println(result);

	}
}

Submission Info

Submission Time
Task B - Friendly Rabbits
User tobi00604
Language Java (OpenJDK 11.0.6)
Score 200
Code Size 478 Byte
Status AC
Exec Time 322 ms
Memory 58660 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 15
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt
Case Name Status Exec Time Memory
0_00.txt AC 113 ms 35416 KB
0_01.txt AC 110 ms 35380 KB
0_02.txt AC 104 ms 35344 KB
1_00.txt AC 109 ms 35480 KB
1_01.txt AC 320 ms 56188 KB
1_02.txt AC 303 ms 58200 KB
1_03.txt AC 297 ms 56532 KB
1_04.txt AC 290 ms 57880 KB
1_05.txt AC 303 ms 58660 KB
1_06.txt AC 322 ms 56228 KB
1_07.txt AC 294 ms 56556 KB
1_08.txt AC 227 ms 52920 KB
1_09.txt AC 278 ms 57116 KB
1_10.txt AC 281 ms 57012 KB
1_11.txt AC 181 ms 45072 KB


2025-03-13 (Thu)
15:35:12 +00:00