結果

問題 No.390 最長の数列
ユーザー FF256grhyFF256grhy
提出日時 2016-07-09 01:48:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 422 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 08:55:22
合計ジャッジ時間 1,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 13 ms
6,944 KB
testcase_06 AC 52 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 24 ms
6,940 KB
testcase_11 AC 24 ms
6,940 KB
testcase_12 AC 23 ms
6,944 KB
testcase_13 AC 17 ms
6,944 KB
testcase_14 AC 29 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:9:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         for(int i = 0; i < n; i++) { scanf("%d", &x); dp[x] = 1; }
      |                                      ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define MAX 1000000

int n, x, dp[MAX + 1];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) { scanf("%d", &x); dp[x] = 1; }
	
	int max = 1;
	for(int i = 1; i <= MAX; i++) {
		if(dp[i]) {
			for(int j = i * 2; j <= MAX; j += i) {
				if(dp[j]) {
					if(dp[j] < dp[i] + 1) { dp[j] = dp[i] + 1; }
					if(max < dp[j]) { max = dp[j]; }
				}
			}
		}
	}
	
	printf("%d\n", max);
	
	return 0;
}
0