結果
問題 | No.390 最長の数列 |
ユーザー |
![]() |
提出日時 | 2017-02-13 17:14:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 569 ms / 5,000 ms |
コード長 | 1,322 bytes |
コンパイル時間 | 1,906 ms |
コンパイル使用メモリ | 165,900 KB |
実行使用メモリ | 7,752 KB |
最終ジャッジ日時 | 2024-10-02 12:07:25 |
合計ジャッジ時間 | 5,345 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF 1000000000 #define PI 3.14159265359 #define EPS 1e-12 int x[101010], dp[1000010]; vector<int> yaku(int n) { vector<int> ans; for(int i=1; i<=sqrt(n); ++i) { if(!(n%i)) { ans.push_back(i); if(i*i != n) ans.push_back(n/i); } } return ans; } int main(void) { int n; cin >> n; REP(i, n) cin >> x[i]; sort(x, x+n); memset(dp, -1, sizeof(dp)); if(x[0] == 1) dp[1] = 1; else dp[1] = 0; REP(i, n) { int maxret = -INF; vector<int> a = yaku(x[i]); sort(ALL(a)); //cout << x[i] << " j:"; for(int j: a) { if(j != x[i] && dp[j] != -1) { //cout << j << " "; maxret = max(maxret, dp[j]); } } //cout << "max:" << maxret << endl; //FOR(i, 1, 10) cout << dp[i] << " "; cout << endl; if(maxret != -INF) dp[x[i]] = maxret+1; } int ans = -INF; for(int i: dp) { ans = max(ans, i); } //FOR(i, 1, 10) cout<<i<<" "<<dp[i]<<endl; cout << ans << endl; return 0; }