結果

問題 No.390 最長の数列
ユーザー FF256grhy
提出日時 2016-07-09 01:48:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 422 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 22,272 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 10:39:25
合計ジャッジ時間 1,071 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
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