結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー | tenten |
提出日時 | 2023-07-19 09:10:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,897 ms / 2,000 ms |
コード長 | 2,254 bytes |
コンパイル時間 | 2,448 ms |
コンパイル使用メモリ | 92,452 KB |
実行使用メモリ | 58,300 KB |
最終ジャッジ日時 | 2024-09-19 07:51:33 |
合計ジャッジ時間 | 23,711 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,897 ms
57,464 KB |
testcase_01 | AC | 75 ms
42,248 KB |
testcase_02 | AC | 78 ms
42,392 KB |
testcase_03 | AC | 82 ms
42,952 KB |
testcase_04 | AC | 80 ms
42,456 KB |
testcase_05 | AC | 74 ms
41,996 KB |
testcase_06 | AC | 79 ms
42,492 KB |
testcase_07 | AC | 78 ms
42,472 KB |
testcase_08 | AC | 77 ms
42,468 KB |
testcase_09 | AC | 75 ms
42,300 KB |
testcase_10 | AC | 102 ms
43,896 KB |
testcase_11 | AC | 73 ms
42,392 KB |
testcase_12 | AC | 78 ms
42,324 KB |
testcase_13 | AC | 1,409 ms
57,108 KB |
testcase_14 | AC | 1,389 ms
57,552 KB |
testcase_15 | AC | 1,437 ms
57,628 KB |
testcase_16 | AC | 1,374 ms
57,644 KB |
testcase_17 | AC | 1,445 ms
57,756 KB |
testcase_18 | AC | 858 ms
56,952 KB |
testcase_19 | AC | 1,806 ms
57,512 KB |
testcase_20 | AC | 516 ms
57,756 KB |
testcase_21 | AC | 541 ms
57,656 KB |
testcase_22 | AC | 1,690 ms
57,524 KB |
testcase_23 | AC | 346 ms
57,636 KB |
testcase_24 | AC | 335 ms
58,300 KB |
testcase_25 | AC | 1,254 ms
57,380 KB |
ソースコード
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(); } }