結果

問題 No.390 最長の数列
ユーザー tentententen
提出日時 2022-10-14 11:41:10
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,838 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 75,228 KB
実行使用メモリ 64,992 KB
最終ジャッジ日時 2023-09-08 19:36:52
合計ジャッジ時間 9,471 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
43,352 KB
testcase_01 AC 37 ms
33,824 KB
testcase_02 AC 37 ms
33,392 KB
testcase_03 AC 36 ms
33,472 KB
testcase_04 AC 37 ms
33,456 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
        ArrayList<HashSet<Integer>> dp = new ArrayList<>();
        dp.add(new HashSet<>());
        for (int i = 0; i < n; i++) {
            boolean exist = false;
            for (int j = dp.size() - 1; j >= 0 && !exist; j--) {
                for (int x : dp.get(j)) {
                    if (values[i] % x == 0) {
                        if (j == dp.size() - 1) {
                            dp.add(new HashSet<>());
                        }
                        dp.get(j + 1).add(values[i]);
                        exist = true;
                        break;
                    }
                }
            }
            if (!exist) {
                dp.get(0).add(values[i]);
            }
        }
        System.out.println(dp.size());
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0