結果

問題 No.390 最長の数列
ユーザー GrenacheGrenache
提出日時 2016-07-10 17:40:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 293 ms / 5,000 ms
コード長 1,778 bytes
コンパイル時間 4,028 ms
コンパイル使用メモリ 79,284 KB
実行使用メモリ 62,968 KB
最終ジャッジ日時 2024-04-10 09:03:25
合計ジャッジ時間 7,862 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
55,688 KB
testcase_01 AC 80 ms
55,828 KB
testcase_02 AC 82 ms
55,480 KB
testcase_03 AC 80 ms
55,496 KB
testcase_04 AC 78 ms
55,620 KB
testcase_05 AC 228 ms
62,700 KB
testcase_06 AC 293 ms
62,744 KB
testcase_07 AC 76 ms
55,516 KB
testcase_08 AC 70 ms
55,340 KB
testcase_09 AC 80 ms
55,528 KB
testcase_10 AC 255 ms
62,964 KB
testcase_11 AC 257 ms
62,684 KB
testcase_12 AC 250 ms
62,832 KB
testcase_13 AC 247 ms
62,968 KB
testcase_14 AC 284 ms
62,792 KB
testcase_15 AC 73 ms
55,484 KB
testcase_16 AC 83 ms
55,180 KB
testcase_17 AC 98 ms
56,436 KB
testcase_18 AC 111 ms
56,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder390_1 {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	Printer pr = new Printer(System.out);

    	int n = sc.nextInt();

    	int[] dp = new int[1_000_000 + 1];
    	for (int i = 0; i < n; i++) {
    		int x = sc.nextInt();
    		dp[x] = 1;
    	}

    	int max = 1;
    	for (int i = 1; i <= 1_000_000; i++) {
    		if (dp[i] == 0) {
    			continue;
    		}
    		for (int j = 2; i * j <= 1_000_000; j++) {
    			if (dp[i * j] == 0) {
    				continue;
    			}

    			dp[i * j] = Math.max(dp[i * j], dp[i] + 1);
    			max = Math.max(max, dp[i * j]);
    		}
    	}

    	pr.println(max);

		sc.close();
        pr.close();
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0