結果

問題 No.979 Longest Divisor Sequence
ユーザー tentententen
提出日時 2023-02-01 08:47:04
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,121 bytes
コンパイル時間 3,162 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 56,232 KB
最終ジャッジ日時 2023-09-13 22:05:49
合計ジャッジ時間 10,470 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,332 KB
testcase_01 AC 45 ms
49,380 KB
testcase_02 AC 44 ms
49,864 KB
testcase_03 AC 44 ms
49,360 KB
testcase_04 AC 45 ms
49,448 KB
testcase_05 AC 44 ms
49,412 KB
testcase_06 AC 44 ms
49,348 KB
testcase_07 AC 45 ms
49,404 KB
testcase_08 AC 45 ms
49,472 KB
testcase_09 AC 45 ms
49,380 KB
testcase_10 AC 231 ms
53,656 KB
testcase_11 AC 223 ms
53,988 KB
testcase_12 AC 234 ms
53,804 KB
testcase_13 AC 293 ms
56,232 KB
testcase_14 TLE -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayList<HashSet<Integer>> list = new ArrayList<>();
        list.add(new HashSet<>());
        for (int i = 0; i < n; i++) {
            int add = 0;
            int target = sc.nextInt();
            for (int j = list.size() - 1; j >= 0 && add == 0; j--) {
                for (int x : list.get(j)) {
                    if (target > x && target % x == 0) {
                        add = j + 1;
                        break;
                    }
                }
            }
            if (add == list.size()) {
                list.add(new HashSet<>());
            }
            list.get(add).add(target);
        }
        System.out.println(list.size());
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0