Submission #890761
Source Code Expand
import java.io.*; import java.util.*; public class Main { FastScanner in; PrintWriter out; void solve() { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt() - 1; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[a[i]] == i) { cnt++; } } out.println(cnt / 2); } void run() { try { in = new FastScanner(new File("object.in")); out = new PrintWriter(new File("object.out")); solve(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } void runIO() { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { new Thread(null, new Runnable() { public void run() { new Main().runIO(); } }, "1", 1 << 26).start(); } }
Submission Info
Submission Time | |
---|---|
Task | B - Friendly Rabbits |
User | qwerty787788 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 200 |
Code Size | 2044 Byte |
Status | AC |
Exec Time | 202 ms |
Memory | 22676 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 | 101 ms | 8424 KB |
0_01.txt | AC | 104 ms | 8400 KB |
0_02.txt | AC | 97 ms | 8428 KB |
1_00.txt | AC | 96 ms | 8432 KB |
1_01.txt | AC | 192 ms | 21880 KB |
1_02.txt | AC | 199 ms | 21768 KB |
1_03.txt | AC | 191 ms | 21772 KB |
1_04.txt | AC | 192 ms | 21904 KB |
1_05.txt | AC | 202 ms | 21852 KB |
1_06.txt | AC | 201 ms | 22676 KB |
1_07.txt | AC | 192 ms | 21784 KB |
1_08.txt | AC | 164 ms | 14164 KB |
1_09.txt | AC | 188 ms | 18484 KB |
1_10.txt | AC | 183 ms | 17592 KB |
1_11.txt | AC | 141 ms | 12244 KB |