結果

問題 No.390 最長の数列
ユーザー TententenTententen
提出日時 2020-12-14 14:42:58
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 883 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 79,468 KB
実行使用メモリ 77,524 KB
最終ジャッジ日時 2023-10-20 05:01:07
合計ジャッジ時間 10,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,536 KB
testcase_01 AC 133 ms
57,440 KB
testcase_02 AC 135 ms
57,480 KB
testcase_03 AC 133 ms
57,772 KB
testcase_04 AC 132 ms
57,476 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.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		ArrayList<ArrayList<Integer>> exists = new ArrayList<>();
		exists.add(new ArrayList<>());
		exists.get(0).add(1);
		for (int i = 0; i < n; i++) {
		    boolean hit = false;
		    for (int j = exists.size() - 1; j >= 0 && !hit; j--) {
		        for (int x : exists.get(j)) {
		            if (arr[i] % x == 0) {
		                if (j == exists.size() - 1) {
		                    exists.add(new ArrayList<>());
		                }
		                exists.get(j + 1).add(arr[i]);
		                hit = true;
		                break;
		            }
		        }
		    }
		}
		System.out.println(exists.size() - 1);
	}
}
0