結果

問題 No.390 最長の数列
ユーザー tentententen
提出日時 2022-08-10 15:32:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,297 ms / 5,000 ms
コード長 1,604 bytes
コンパイル時間 4,389 ms
コンパイル使用メモリ 83,940 KB
実行使用メモリ 68,104 KB
最終ジャッジ日時 2023-10-21 01:31:39
合計ジャッジ時間 13,101 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,640 KB
testcase_01 AC 54 ms
53,644 KB
testcase_02 AC 53 ms
51,616 KB
testcase_03 AC 53 ms
53,644 KB
testcase_04 AC 54 ms
53,652 KB
testcase_05 AC 1,297 ms
68,104 KB
testcase_06 AC 976 ms
66,328 KB
testcase_07 AC 56 ms
53,648 KB
testcase_08 AC 56 ms
53,652 KB
testcase_09 AC 59 ms
53,648 KB
testcase_10 AC 1,068 ms
64,268 KB
testcase_11 AC 1,085 ms
64,440 KB
testcase_12 AC 1,107 ms
65,768 KB
testcase_13 AC 602 ms
63,940 KB
testcase_14 AC 639 ms
64,428 KB
testcase_15 AC 55 ms
53,648 KB
testcase_16 AC 59 ms
53,660 KB
testcase_17 AC 193 ms
56,988 KB
testcase_18 AC 209 ms
59,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        int max = 0;
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int j = 0; j < n; j++) {
            int x = values[j];
            int v = counts.getOrDefault(1, 0) + 1;
            for (int i = 2; i <= Math.sqrt(x); i++) {
                if (x % i == 0) {
                    v = Math.max(v, counts.getOrDefault(i, 0) + 1);
                    v = Math.max(v, counts.getOrDefault(x / i, 0) + 1);
                }
            }
            max = Math.max(max, v);
            counts.put(x, v);
        }
        System.out.println(max);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0