結果

問題 No.390 最長の数列
ユーザー furu_tuwwfuru_tuww
提出日時 2016-07-08 23:37:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 444 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 56,484 KB
実行使用メモリ 8,268 KB
最終ジャッジ日時 2024-04-21 08:31:18
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 71 ms
7,936 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 28 ms
8,012 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 40 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 5 ms
7,888 KB
testcase_18 AC 6 ms
8,064 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[111111];
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