結果

問題 No.390 最長の数列
ユーザー akakimidoriakakimidori
提出日時 2017-04-27 13:47:33
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 528 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 10:20:30
合計ジャッジ時間 1,393 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 32 ms
6,940 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 19 ms
6,940 KB
testcase_11 AC 22 ms
6,944 KB
testcase_12 AC 19 ms
6,940 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 32 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:8:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:14:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d",&x);
      |     ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

void run(void){
  int n;
  scanf("%d",&n);
  const int m=1000000;
  int *e=(int *)calloc(m+1,sizeof(int));
  int i;
  for(i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    e[x]++;
  }



  for(i=m/2;i>=1;i--){
    if(e[i]>0){
      int j;
      for(j=2*i;j<=m;j+=i){
	e[i]=MAX(e[i],e[j]+1);
      }
    }
  }
  int ans=0;
  for(i=1;i<=m;i++){
    ans=MAX(ans,e[i]);
  }
  printf("%d\n",ans);
  free(e);
  return;
}

int main(void){
  run();
  return 0;
}
0