|
| 1 | +```java |
| 2 | +import java.io.BufferedReader; |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStreamReader; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.HashSet; |
| 8 | +import java.util.StringTokenizer; |
| 9 | + |
| 10 | + |
| 11 | +public class Main { |
| 12 | + |
| 13 | + static int numCnt,ans; |
| 14 | + static int[] arr; |
| 15 | + static HashMap<Integer,HashSet<Integer>> good; |
| 16 | + |
| 17 | + public static void main(String[] args) throws IOException { |
| 18 | + init(); |
| 19 | + process(); |
| 20 | + print(); |
| 21 | + } |
| 22 | + |
| 23 | + public static void init() throws IOException { |
| 24 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 25 | + good = new HashMap<>(); |
| 26 | + |
| 27 | + numCnt = Integer.parseInt(br.readLine()); |
| 28 | + arr =new int[numCnt]; |
| 29 | + ans = 0; |
| 30 | + |
| 31 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 32 | + for (int i = 0; i < numCnt; i++) { |
| 33 | + arr[i] = Integer.parseInt(st.nextToken()); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public static void process() throws IOException { |
| 38 | + for (int i = 0; i <numCnt; i++) { |
| 39 | + if (good.containsKey(arr[i])) { |
| 40 | + good.get(arr[i]).add(i); |
| 41 | + } else { |
| 42 | + good.put(arr[i], new HashSet<>()); |
| 43 | + good.get(arr[i]).add(i); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + for (int i = 0; i < numCnt; i++) { |
| 49 | + for (int j = i+1; j < numCnt; j++){ |
| 50 | + int sum = arr[i] + arr[j]; |
| 51 | + |
| 52 | + if (!good.containsKey(sum)) continue; |
| 53 | + |
| 54 | + HashSet<Integer> idx = good.get(sum); |
| 55 | + |
| 56 | + boolean isRemovable = false; |
| 57 | + |
| 58 | + for (int n: idx) { |
| 59 | + if (n != i && n != j) { |
| 60 | + isRemovable = true; |
| 61 | + break; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + if (isRemovable) good.remove(sum); |
| 66 | + |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + int zeroCnt = 0; |
| 71 | + for (int i = 0; i < numCnt; i++) if(arr[i] == 0) zeroCnt++; |
| 72 | + if (zeroCnt >= 3) good.remove(0); |
| 73 | + |
| 74 | + for (int i = 0; i < numCnt; i++) { |
| 75 | + if (!good.containsKey(arr[i])) ans++; |
| 76 | + } |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + public static void print() { |
| 83 | + System.out.println(ans); |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +``` |
0 commit comments