結果

問題 No.390 最長の数列
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-14 10:44:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 892 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 79,448 KB
実行使用メモリ 74,072 KB
最終ジャッジ日時 2024-04-10 10:21:33
合計ジャッジ時間 10,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
54,072 KB
testcase_01 AC 119 ms
54,220 KB
testcase_02 AC 107 ms
52,852 KB
testcase_03 AC 115 ms
53,948 KB
testcase_04 AC 103 ms
52,980 KB
testcase_05 AC 668 ms
66,172 KB
testcase_06 AC 892 ms
74,072 KB
testcase_07 AC 117 ms
53,956 KB
testcase_08 AC 120 ms
57,188 KB
testcase_09 AC 121 ms
57,228 KB
testcase_10 AC 773 ms
66,388 KB
testcase_11 AC 792 ms
66,292 KB
testcase_12 AC 808 ms
66,052 KB
testcase_13 AC 471 ms
65,528 KB
testcase_14 AC 684 ms
66,076 KB
testcase_15 AC 118 ms
53,972 KB
testcase_16 AC 139 ms
58,408 KB
testcase_17 AC 237 ms
63,008 KB
testcase_18 AC 272 ms
61,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> xList = new ArrayList<Integer>();
    for(int i = 0; i < N; i++) {
      xList.add(sc.nextInt());
    }
    Collections.sort(xList);
    int A = xList.get(xList.size() - 1);
    int[] dp = new int[A + 1];
    for(int i = 0; i < xList.size(); i++) {
      dp[xList.get(i)] = 1;
    }
    int ans = 0;
    for(int i = 1; i < A + 1; i++) {
      ans = Math.max(ans, dp[i]);
      if(dp[i] > 0) {
        for(int j = 2 * i; j < A + 1; j += i) {
          if(dp[j] > 0) dp[j] = Math.max(dp[j], 1 + dp[i]);
        }
      }
    }
    System.out.println(ans);
  }
}
0