結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
furu_tuww
|
| 提出日時 | 2016-07-08 23:41:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 69 ms / 5,000 ms |
| コード長 | 445 bytes |
| コンパイル時間 | 565 ms |
| コンパイル使用メモリ | 56,920 KB |
| 実行使用メモリ | 11,988 KB |
| 最終ジャッジ日時 | 2024-10-02 10:36:23 |
| 合計ジャッジ時間 | 1,640 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d",&x);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int f[1111111];
int dp[1111111];
int solve(int k){
if(dp[k]) return dp[k];
int ret = 0;
for(int i = 2; k*i <= 1000000; i++){
if(f[k*i])
ret = max(ret,1+solve(k*i));
}
return dp[k] = ret;
}
int main(void){
scanf("%d",&n);
for(int i = 0; i < n; i++){
int x;
scanf("%d",&x);
f[x]++;
}
printf("%d\n",solve(1)+f[1]);
}
furu_tuww