結果

問題 No.390 最長の数列
ユーザー yun_appyun_app
提出日時 2016-12-01 15:31:09
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,561 bytes
コンパイル時間 2,675 ms
コンパイル使用メモリ 75,940 KB
実行使用メモリ 70,540 KB
最終ジャッジ日時 2023-08-18 11:20:45
合計ジャッジ時間 9,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
56,624 KB
testcase_01 AC 41 ms
49,540 KB
testcase_02 AC 41 ms
49,492 KB
testcase_03 AC 42 ms
49,900 KB
testcase_04 AC 42 ms
49,264 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.*;
import java.lang.*;
import java.io.*;
class Main{
    public static void main (String[] args) throws java.lang.Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] lines = br.readLine().toString().split(" ");
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(String st:lines){
            list.add(Integer.parseInt(st));
        }
        Collections.sort(list);
        
        HashMap<Integer,ArrayList<Integer>> map = new HashMap<Integer,ArrayList<Integer>>();
        for(int i=0;i<list.size();i++){
            ArrayList<Integer> next = new ArrayList<Integer>();
            map.put(i,next);
            int now = list.get(i);
            for(int j=i+1;j<list.size();j++){
                if(list.get(j)%now == 0){
                    next.add(j);
                }
            }
        }
        
        int ans = calc(map,0,n);
        System.out.println(ans);
        
    }
    
    static HashMap<Integer,Integer> ans_map = new HashMap<Integer,Integer>();
    public static int calc(HashMap<Integer,ArrayList<Integer>> map,int idx,int n){
        if(ans_map.containsKey(idx)){
            return ans_map.get(idx);
        }
        int max = 1;
        for(int i=idx;i<n;i++){
            ArrayList<Integer> next = map.get(i);
            for(int j:next){
                max = Math.max(max,calc(map,j,n)+1);
            }
        }
        ans_map.put(idx,max);
        return max;
    }

}
0