結果

問題 No.979 Longest Divisor Sequence
ユーザー tentententen
提出日時 2020-08-25 09:25:49
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,460 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 79,820 KB
実行使用メモリ 65,368 KB
最終ジャッジ日時 2024-04-24 04:12:45
合計ジャッジ時間 9,215 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
45,436 KB
testcase_01 AC 112 ms
41,440 KB
testcase_02 AC 114 ms
41,308 KB
testcase_03 AC 114 ms
41,300 KB
testcase_04 AC 109 ms
39,964 KB
testcase_05 AC 112 ms
41,136 KB
testcase_06 AC 101 ms
40,056 KB
testcase_07 AC 112 ms
40,128 KB
testcase_08 AC 115 ms
41,272 KB
testcase_09 AC 110 ms
40,328 KB
testcase_10 AC 474 ms
50,976 KB
testcase_11 AC 444 ms
47,484 KB
testcase_12 AC 340 ms
46,400 KB
testcase_13 AC 703 ms
57,928 KB
testcase_14 TLE -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<HashSet<Integer>> list = new ArrayList<>();
        list.add(new HashSet<>());
        list.get(0).add(sc.nextInt());
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            boolean flag = false;
            for (int y : list.get(0)) {
                if (x % y == 0 && x > y) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                list.get(0).add(x);
                continue;
            }
            int left = 0;
            int right = list.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                boolean exist = false;
                for (int y : list.get(m)) {
                    if (x % y == 0 && x > y) {
                        exist = true;
                        break;
                    }
                }
                if (exist) {
                    left = m;
                } else {
                    right = m;
                }
            }
            if (left == list.size() - 1) {
                list.add(new HashSet<>());
            }
            list.get(left + 1).add(x);
            
        }
        System.out.println(list.size());
    }
}
0