結果

問題 No.390 最長の数列
ユーザー furu_tuwwfuru_tuww
提出日時 2016-07-08 23:41:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 445 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 56,264 KB
実行使用メモリ 11,992 KB
最終ジャッジ日時 2024-04-10 08:52:31
合計ジャッジ時間 1,666 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 71 ms
11,980 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 33 ms
11,992 KB
testcase_11 AC 34 ms
11,600 KB
testcase_12 AC 32 ms
11,900 KB
testcase_13 AC 23 ms
11,856 KB
testcase_14 AC 45 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 4 ms
8,012 KB
testcase_17 AC 8 ms
11,868 KB
testcase_18 AC 10 ms
11,876 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#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]);
}
0