結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー tentententen
提出日時 2023-03-27 10:55:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,339 bytes
コンパイル時間 4,279 ms
コンパイル使用メモリ 92,368 KB
実行使用メモリ 68,356 KB
最終ジャッジ日時 2023-10-19 14:01:37
合計ジャッジ時間 28,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 75 ms
42,036 KB
testcase_02 AC 75 ms
42,024 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 73 ms
41,872 KB
testcase_09 AC 72 ms
41,636 KB
testcase_10 WA -
testcase_11 AC 74 ms
42,092 KB
testcase_12 AC 74 ms
42,080 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 921 ms
52,008 KB
testcase_19 AC 1,996 ms
65,464 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,761 ms
54,016 KB
testcase_23 AC 309 ms
49,556 KB
testcase_24 AC 297 ms
49,456 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] counts = new int[1000001];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            for (int j = 1; j <= Math.sqrt(x); j++) {
                if (x % j == 0) {
                    counts[j]++;
                    if (j * j < x) {
                        counts[x / j]++;
                    }
                }
            }
        }
        HashMap<Integer, Integer> values = new HashMap<>();
        for (int i = 1; i <= 1000000; i++) {
            if (counts[i] == 0) {
                continue;
            }
            values.put(counts[i], i);
        }
        int current = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = n; i > 0; i--) {
            if (values.containsKey(i)) {
                current = values.get(i);
            }
            sb.append(current).append("\n");
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0