結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2016-07-09 10:46:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 5,000 ms |
| コード長 | 1,290 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 49,716 KB |
| 実行使用メモリ | 7,948 KB |
| 最終ジャッジ日時 | 2024-10-02 10:40:55 |
| 合計ジャッジ時間 | 1,456 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~
ソースコード
// #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;
}
rickytheta