結果

問題 No.979 Longest Divisor Sequence
ユーザー tko919tko919
提出日時 2020-01-31 23:25:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 171,476 KB
実行使用メモリ 38,252 KB
最終ジャッジ日時 2023-10-17 12:41:17
合計ジャッジ時間 10,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 471 ms
36,960 KB
testcase_01 AC 475 ms
36,960 KB
testcase_02 AC 456 ms
36,960 KB
testcase_03 AC 476 ms
36,960 KB
testcase_04 AC 460 ms
36,960 KB
testcase_05 AC 456 ms
36,960 KB
testcase_06 AC 455 ms
36,960 KB
testcase_07 AC 465 ms
36,960 KB
testcase_08 AC 448 ms
36,960 KB
testcase_09 AC 443 ms
36,960 KB
testcase_10 AC 456 ms
36,960 KB
testcase_11 AC 456 ms
36,960 KB
testcase_12 AC 472 ms
36,960 KB
testcase_13 AC 503 ms
38,252 KB
testcase_14 AC 546 ms
38,252 KB
testcase_15 AC 487 ms
37,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

vector<int> res(301000,0),g[301000];

int main(){
   rep(i,1,300001){
	   for(int j=2*i;j<=300000;j+=i)g[j].push_back(i);
   }
   int n; scanf("%d",&n);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   rep(i,0,n){
	   if(a[i]==1)chmax(res[a[i]],1);
	   else{
		   for(int pre:g[a[i]]){
			   chmax(res[a[i]],res[pre]+1);
		   }
	   }
   }
   printf("%d\n",*max_element(ALL(res)));
   return 0;
}
0