結果

問題 No.2218 Multiple LIS
ユーザー tentententen
提出日時 2023-02-20 10:59:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,976 ms / 3,000 ms
コード長 2,575 bytes
コンパイル時間 3,385 ms
コンパイル使用メモリ 92,084 KB
実行使用メモリ 91,852 KB
最終ジャッジ日時 2023-09-28 10:12:28
合計ジャッジ時間 25,679 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,456 KB
testcase_01 AC 40 ms
49,528 KB
testcase_02 AC 40 ms
49,500 KB
testcase_03 AC 39 ms
49,488 KB
testcase_04 AC 39 ms
49,468 KB
testcase_05 AC 38 ms
49,304 KB
testcase_06 AC 39 ms
49,556 KB
testcase_07 AC 38 ms
49,380 KB
testcase_08 AC 38 ms
49,260 KB
testcase_09 AC 38 ms
49,332 KB
testcase_10 AC 39 ms
49,392 KB
testcase_11 AC 39 ms
49,356 KB
testcase_12 AC 47 ms
49,648 KB
testcase_13 AC 78 ms
51,860 KB
testcase_14 AC 63 ms
51,816 KB
testcase_15 AC 68 ms
51,908 KB
testcase_16 AC 46 ms
49,636 KB
testcase_17 AC 77 ms
51,864 KB
testcase_18 AC 42 ms
49,476 KB
testcase_19 AC 47 ms
49,688 KB
testcase_20 AC 62 ms
52,092 KB
testcase_21 AC 149 ms
57,852 KB
testcase_22 AC 561 ms
67,332 KB
testcase_23 AC 679 ms
68,460 KB
testcase_24 AC 256 ms
59,092 KB
testcase_25 AC 839 ms
70,096 KB
testcase_26 AC 1,186 ms
72,488 KB
testcase_27 AC 1,174 ms
71,988 KB
testcase_28 AC 1,133 ms
72,604 KB
testcase_29 AC 921 ms
69,736 KB
testcase_30 AC 748 ms
70,892 KB
testcase_31 AC 1,462 ms
67,836 KB
testcase_32 AC 1,976 ms
70,660 KB
testcase_33 AC 1,548 ms
70,332 KB
testcase_34 AC 1,446 ms
67,524 KB
testcase_35 AC 1,425 ms
70,184 KB
testcase_36 AC 244 ms
75,744 KB
testcase_37 AC 604 ms
86,648 KB
testcase_38 AC 39 ms
49,304 KB
testcase_39 AC 39 ms
49,484 KB
testcase_40 AC 805 ms
91,852 KB
testcase_41 AC 831 ms
89,720 KB
権限があれば一括ダウンロードができます

ソースコード

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>> results = new ArrayList<>();
        results.add(new HashSet<>());
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ArrayList<Integer> unit = new ArrayList<>();
            for (int j = 1; j <= Math.sqrt(x); j++) {
                if (x % j == 0) {
                    unit.add(j);
                    if (j * j < x) {
                        unit.add(x / j);
                    }
                }
            }
            boolean enable = false;
            for (int j = results.size() - 1; j >= 0 && !enable; j--) {
                for (int y : unit) {
                    if (results.get(j).contains(y)) {
                        if (j == results.size() - 1) {
                            results.add(new HashSet<>());
                        }
                        results.get(j + 1).add(x);
                        enable = true;
                        break;
                    }
                }
            }
            if (!enable) {
                results.get(0).add(x);
            }
        }
        System.out.println(results.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