結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー ks2mks2m
提出日時 2021-11-05 22:03:20
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,335 bytes
コンパイル時間 2,860 ms
コンパイル使用メモリ 78,732 KB
実行使用メモリ 77,996 KB
最終ジャッジ日時 2024-04-24 05:51:16
合計ジャッジ時間 25,205 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 68 ms
54,688 KB
testcase_02 AC 69 ms
55,028 KB
testcase_03 AC 76 ms
55,572 KB
testcase_04 AC 79 ms
55,740 KB
testcase_05 AC 76 ms
55,476 KB
testcase_06 AC 94 ms
55,864 KB
testcase_07 AC 76 ms
55,448 KB
testcase_08 AC 70 ms
54,928 KB
testcase_09 AC 92 ms
56,128 KB
testcase_10 AC 102 ms
56,148 KB
testcase_11 AC 73 ms
55,352 KB
testcase_12 AC 68 ms
55,008 KB
testcase_13 AC 1,331 ms
76,736 KB
testcase_14 AC 1,238 ms
75,688 KB
testcase_15 AC 1,305 ms
75,664 KB
testcase_16 AC 1,267 ms
75,420 KB
testcase_17 AC 1,243 ms
75,856 KB
testcase_18 AC 929 ms
74,840 KB
testcase_19 AC 1,497 ms
75,772 KB
testcase_20 AC 915 ms
77,996 KB
testcase_21 AC 881 ms
77,596 KB
testcase_22 TLE -
testcase_23 AC 461 ms
76,452 KB
testcase_24 AC 465 ms
76,564 KB
testcase_25 AC 1,225 ms
76,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] cnt = new int[1000001];
		for (int i = 0; i < n; i++) {
			List<Integer> list = divList(a[i]);
			for (int e : list) {
				cnt[e]++;
			}
		}

		int[] ans = new int[n];
		for (int i = 1000000; i > 0; i--) {
			if (cnt[i] > 0) {
				int x = n - cnt[i];
				if (ans[x] == 0) {
					ans[x] = i;
				}
			}
		}
		for (int i = 1; i < n; i++) {
			ans[i] = Math.max(ans[i], ans[i - 1]);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i : ans) {
			pw.println(i);
		}
		pw.flush();
	}

	static List<Integer> divList(int n) {
		List<Integer> list = new ArrayList<>();
		int end = (int) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				list.add(i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		return list;
	}
}
0