結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー tentententen
提出日時 2023-07-19 09:10:04
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,254 bytes
コンパイル時間 3,806 ms
コンパイル使用メモリ 84,612 KB
実行使用メモリ 70,768 KB
最終ジャッジ日時 2023-10-19 11:45:13
合計ジャッジ時間 27,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 82 ms
42,052 KB
testcase_02 AC 80 ms
41,736 KB
testcase_03 AC 83 ms
42,140 KB
testcase_04 AC 83 ms
42,164 KB
testcase_05 AC 86 ms
42,140 KB
testcase_06 AC 86 ms
42,320 KB
testcase_07 AC 83 ms
41,808 KB
testcase_08 AC 91 ms
42,552 KB
testcase_09 AC 80 ms
41,740 KB
testcase_10 AC 105 ms
43,556 KB
testcase_11 AC 80 ms
41,788 KB
testcase_12 AC 84 ms
42,056 KB
testcase_13 AC 1,555 ms
57,464 KB
testcase_14 AC 1,538 ms
57,356 KB
testcase_15 AC 1,558 ms
57,356 KB
testcase_16 AC 1,548 ms
57,560 KB
testcase_17 AC 1,560 ms
57,336 KB
testcase_18 AC 942 ms
58,488 KB
testcase_19 AC 1,993 ms
70,768 KB
testcase_20 AC 590 ms
57,400 KB
testcase_21 AC 591 ms
57,364 KB
testcase_22 AC 1,859 ms
57,220 KB
testcase_23 AC 355 ms
57,436 KB
testcase_24 AC 357 ms
58,384 KB
testcase_25 AC 1,379 ms
57,324 KB
権限があれば一括ダウンロードができます

ソースコード

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]++;
                    }
                }
            }
        }
        int[] ans = new int[n];
        for (int i = 1; i < counts.length; i++) {
            if (counts[i] > 0) {
                ans[n - counts[i]] = i;
            }
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            ans[i] = Math.max(max, ans[i]);
            max = ans[i];
        }
        System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
    }
}
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