結果

問題 No.390 最長の数列
ユーザー rickythetarickytheta
提出日時 2016-07-09 10:46:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,290 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 49,580 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2024-04-10 08:56:32
合計ジャッジ時間 1,362 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,816 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 7 ms
6,940 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 7 ms
6,944 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 64 ms
7,792 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 23 ms
7,588 KB
testcase_11 AC 22 ms
7,812 KB
testcase_12 AC 21 ms
7,968 KB
testcase_13 AC 22 ms
7,704 KB
testcase_14 AC 45 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 5 ms
7,168 KB
testcase_18 AC 7 ms
7,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:52:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |     scanf("%d",x+i);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

// #include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

typedef vector<int> vi;

int n;
int x[125252];
int dp[1<<20];

void radix_sort(){
  vi buc[2][16];
  int tm=0;
  REP(i,n){
    int y = x[i];
    buc[tm][y&15].push_back(y);
  }
  FOR(k,1,5){
    int wd = 4*k;
    FORR(j,0,16){
      REP(i,buc[tm][j].size()){
        int y = buc[tm][j][i];
        buc[tm^1][(y>>wd)&15].push_back(y);
      }
      buc[tm][j].clear();
    }
    tm ^= 1;
  }
  int it=0;
  FORR(j,0,16){
    REP(i,buc[tm][j].size()){
      x[it++] = buc[tm][j][i];
    }
  }
}

int main(){
  vector<bool> has(1<<20,false);
  int ans = 1;

  scanf("%d",&n);
  REP(i,n){
    scanf("%d",x+i);
    has[x[i]] = true;
  }
  radix_sort();
  // sort(x,x+n,greater<int>());
  REP(i,n){
    int y = x[i];
    int it = y;
    if(dp[y]==0)dp[y]=1;
    for(int it=2*y;it<(1<<20);it+=y){
      if(!has[it])continue;
      if(dp[y]<=dp[it])dp[y]=dp[it]+1;
    }
    if(ans<dp[y])ans=dp[y];
  }
  printf("%d\n",ans);
  return 0;
}
0