結果

問題 No.390 最長の数列
ユーザー htensaihtensai
提出日時 2019-11-20 13:00:17
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,365 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 78,568 KB
実行使用メモリ 76,468 KB
最終ジャッジ日時 2024-04-15 21:37:44
合計ジャッジ時間 10,290 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
61,152 KB
testcase_01 AC 137 ms
54,296 KB
testcase_02 AC 139 ms
54,312 KB
testcase_03 AC 137 ms
54,112 KB
testcase_04 AC 138 ms
54,032 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.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		TreeSet<Unit> set = new TreeSet<>();
		int max = 1;
		for (int i = n - 1; i >= 0; i--) {
		    boolean flag = true;
		    for (Unit u : set) {
		        if (u.value % arr[i] == 0) {
		            set.add(new Unit(i, arr[i], u.count + 1));
		            max = Math.max(max, u.count + 1);
		            flag = false;
		            break;
		        }
		    }
		    if (flag) {
		       set.add(new Unit(i, arr[i], 1));
		    }
		}
		System.out.println(max);
	}
	
	static class Unit implements Comparable<Unit> {
	    int idx;
	    int value;
	    int count;
	    
	    public Unit (int idx, int value, int count) {
	        this.idx = idx;
	        this.value = value;
	        this.count = count;
	    }
	    
	    public int hashCode() {
	        return idx;
	    }
	    
	    public int compareTo(Unit another) {
	        if (count == another.count) {
	            return idx - another.idx;
	        } else {
	            return another.count - count;
	        }
	    }
	    
	    public boolean equals(Object o) {
	        Unit u = (Unit) o;
	        return idx == u.idx && count == u.count;
	    }
	}
}
0