Submission #890881
Source Code Expand
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class Main { public static void main(String[] args) throws IOException { final Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = sc.nextInt() - 1; } long count = 0; for(int i = 0; i < N; i++){ if(arr[arr[i]] == i){ count++; } } System.out.println(count / 2); } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public void close() throws IOException { br.close(); } } }
Submission Info
Submission Time | |
---|---|
Task | B - Friendly Rabbits |
User | tshirakawa |
Language | Java8 (OpenJDK 1.8.0) |
Score | 200 |
Code Size | 1877 Byte |
Status | AC |
Exec Time | 213 ms |
Memory | 22232 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
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 | 98 ms | 8144 KB |
0_01.txt | AC | 97 ms | 8016 KB |
0_02.txt | AC | 127 ms | 8020 KB |
1_00.txt | AC | 99 ms | 8148 KB |
1_01.txt | AC | 213 ms | 22232 KB |
1_02.txt | AC | 210 ms | 22104 KB |
1_03.txt | AC | 190 ms | 21456 KB |
1_04.txt | AC | 201 ms | 21540 KB |
1_05.txt | AC | 201 ms | 21540 KB |
1_06.txt | AC | 193 ms | 21584 KB |
1_07.txt | AC | 205 ms | 21540 KB |
1_08.txt | AC | 167 ms | 14036 KB |
1_09.txt | AC | 196 ms | 19456 KB |
1_10.txt | AC | 194 ms | 17932 KB |
1_11.txt | AC | 145 ms | 11860 KB |