結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,812 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 7 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 14 ms
6,948 KB
testcase_06 AC 62 ms
8,076 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 23 ms
7,792 KB
testcase_11 AC 27 ms
7,684 KB
testcase_12 AC 22 ms
7,776 KB
testcase_13 AC 21 ms
8,276 KB
testcase_14 AC 46 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 6 ms
7,296 KB
testcase_18 AC 6 ms
7,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     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];

#define BUC_SHIFT 5
#define BUC_SIZE 32
#define BUC_MASK 31
void radix_sort(){
  vi buc[2][BUC_SIZE];
  int tm=0;
  REP(i,n){
    int y = x[i];
    buc[tm][y&BUC_MASK].push_back(y);
  }
  FOR(k,1,4){
    int wd = BUC_SHIFT*k;
    FORR(j,0,BUC_SIZE){
      REP(i,buc[tm][j].size()){
        int y = buc[tm][j][i];
        buc[tm^1][(y>>wd)&BUC_MASK].push_back(y);
      }
      buc[tm][j].clear();
    }
    tm ^= 1;
  }
  int it=0;
  FORR(j,0,BUC_SIZE){
    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