|
| 1 | +```java |
| 2 | +import java.util.*; |
| 3 | +import java.io.*; |
| 4 | + |
| 5 | +public class Main{ |
| 6 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 7 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 8 | + static StringTokenizer st; |
| 9 | + static int N; |
| 10 | + static int[] playerCard; |
| 11 | + static int[] playerScore; |
| 12 | + static boolean[] exist; |
| 13 | + static HashMap<Integer,Integer> idx; |
| 14 | + |
| 15 | + public static void main(String[] args) throws Exception{ |
| 16 | + N = Integer.parseInt(br.readLine()); |
| 17 | + playerScore = new int[N+1]; |
| 18 | + playerCard = new int[N+1]; |
| 19 | + exist = new boolean[1000001]; |
| 20 | + idx = new HashMap<>(); |
| 21 | + st = new StringTokenizer(br.readLine()); |
| 22 | + |
| 23 | + int max = 0; |
| 24 | + for (int i = 1; i <= N; i++) { |
| 25 | + playerCard[i] = Integer.parseInt(st.nextToken()); |
| 26 | + exist[playerCard[i]] = true; |
| 27 | + idx.put(playerCard[i],i); |
| 28 | + max = Math.max(max, playerCard[i]); |
| 29 | + } |
| 30 | + |
| 31 | + for (int i = 1; i <= N; i++) { |
| 32 | + for(int j = playerCard[i]; j <= max; j+=playerCard[i]) { |
| 33 | + if(exist[j]){ |
| 34 | + playerScore[i]++; |
| 35 | + playerScore[idx.get(j)]--; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + StringBuffer sb = new StringBuffer(); |
| 40 | + for (int i = 1; i <= N; i++) { |
| 41 | + sb.append(playerScore[i]).append(" "); |
| 42 | + } |
| 43 | + bw.write(sb.toString()); |
| 44 | + bw.close(); |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
0 commit comments